You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ofbiz.apache.org by "Jacques Le Roux (JIRA)" <ji...@apache.org> on 2016/05/10 11:24:12 UTC
[jira] [Commented] (OFBIZ-4427) Possible runtime errors with
UtilValidate.isEmpty(Object) should be rather caught during compilation
[ https://issues.apache.org/jira/browse/OFBIZ-4427?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15277956#comment-15277956 ]
Jacques Le Roux commented on OFBIZ-4427:
----------------------------------------
I tried to apply the patch. There are 11 rejected hunks. So I decided to go by hand for those but stumbled upon this in InvoiceWorker.java (1st hunk I tried to handle by hand)
{code}
@@ -519,12 +519,12 @@
conversionRate = acctgTransEntry.getBigDecimal("amount").divide(acctgTransEntry.getBigDecimal("origAmount"), new MathContext(100)).setScale(decimals,rounding);
}
// check if a payment is applied and use the currency conversion from there
- if (UtilValidate.isEmpty(conversionRate)) {
+ if (conversionRate == null) {
List<GenericValue> paymentAppls = invoice.getRelated("PaymentApplication");
for (GenericValue paymentAppl : paymentAppls) {
GenericValue payment = paymentAppl.getRelatedOne("Payment");
- if (UtilValidate.isNotEmpty(payment.getBigDecimal("actualCurrencyAmount"))) {
- if (UtilValidate.isEmpty(conversionRate)) {
+ if (payment.getBigDecimal("actualCurrencyAmount") != null) {
+ if (conversionRate == null) {
conversionRate = payment.getBigDecimal("amount").divide(payment.getBigDecimal("actualCurrencyAmount"),new MathContext(100)).setScale(decimals,rounding);
} else {
conversionRate = conversionRate.add(payment.getBigDecimal("amount").divide(payment.getBigDecimal("actualCurrencyAmount"),new MathContext(100))).divide(new BigDecimal("2"),new MathContext(100)).setScale(decimals,rounding);
{code}
Obviously the second test on "_conversionRate == null_" does not make sense because conversionRate would be necessarily null in the whole block. But I guess that the 2 "_conversionRate = ....._" cases were implemented for a reason. So I did not dig furter and decided to stop there and to close this as won't fix, better to not introduce troubles...
> Possible runtime errors with UtilValidate.isEmpty(Object) should be rather caught during compilation
> ----------------------------------------------------------------------------------------------------
>
> Key: OFBIZ-4427
> URL: https://issues.apache.org/jira/browse/OFBIZ-4427
> Project: OFBiz
> Issue Type: Improvement
> Components: framework
> Affects Versions: Trunk
> Reporter: Jacques Le Roux
> Assignee: Jacques Le Roux
> Priority: Minor
> Labels: UtilValidate.isEmpty
> Attachments: OFBIZ-4427.patch, OFBIZ-4427_isEmpty.patch
>
>
> Hence we need to remove the UtilValidate.isEmpty(Object) method and provide methods that accept explicit types.
> Scripting languages should use a facade class that provides methods for working with generic Objects or providing default behaviors.
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)