simpleqt opened a new pull request, #421:
URL: https://github.com/apache/commons-jexl/pull/421

   `JexlArithmetic.isEmpty(Object, Boolean)` tests a `Number` for emptiness by 
converting it to a `double` and comparing with zero 
(`JexlArithmetic.java:1116-1119`):
   
   ```java
   final double d = ((Number) object).doubleValue();
   return Double.isNaN(d) || d == 0.d;
   ```
   
   `BigDecimal` and `BigInteger` are unbounded, so a non-zero value whose 
magnitude is below `Double.MIN_VALUE` underflows to `0.0` and is reported as 
empty although it is not zero:
   
   ```java
   final JexlScript s = new JexlBuilder().create().createScript("empty(x)", 
"x");
   s.execute(null, new BigDecimal("1E-400"));   // true, expected false
   s.execute(null, new BigDecimal("-1E-400"));  // true, expected false
   ```
   
   `empty x` (the unary operator) behaves the same, and the value is not zero 
by any measure: `signum()` is non-zero, `compareTo(BigDecimal.ZERO)` is 
positive, and arithmetic keeps it alive (`1E-400 + 1E-400 == 2E-400`). Only 
`BigDecimal`/`BigInteger` reach this: every bounded `Number` (including `Long`, 
whose identical defect was JEXL-163) fits in a `double`, so the conversion is 
lossless enough there. The same double comparison was also incidental for 
magnitudes above `Double.MAX_VALUE`, where the conversion yields an infinity 
that happened to be non-empty.
   
   Fix: use the sign of the unbounded number, `signum() == 0`, for `BigDecimal` 
and `BigInteger`; all other `Number` types keep the existing double-based test, 
so zero values, `Double.NaN` and the `AtomicInteger`/`AtomicLong` behavior are 
unchanged.
   
   Validation:
   
   - New test `ArithmeticTest#testEmptyBigNumberMagnitudes` covers `1E-400`, 
`1E-320`, `-1E-400`, `1E400`, `1E5000`, `BigInteger("-1")` as non-empty and 
`0`, `0E-400`, `0.0000`, `BigInteger.ZERO` as empty, through `empty(x)`, `empty 
x` and `x.empty()`.
   - It fails on the pre-fix base (`expected: <false> but was: <true>`) and 
passes with the fix.
   - Full `mvn test` passes: 1216 tests, 0 failures; checkstyle reports 0 
violations.
   
   No `src/changes/changes.xml` entry is included because the action format 
requires a JIRA issue key and I do not have a JIRA account. Happy to add one, 
e.g.:
   
   ```xml
   <action dev="simpleqt" due-to="simpleqt" type="fix" issue="JEXL-xxx">empty() 
now considers a non-zero BigDecimal or BigInteger with a magnitude outside the 
double range as non-empty.</action>
   ```
   
   AI assistance used to diagnose and fix this defect; the analysis and the 
change have been reviewed and verified as described above.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to