-
Bug
-
Resolution: Fixed
-
P3
-
21
Issue | Fix Version | Assignee | Priority | Status | Resolution | Resolved In Build |
---|---|---|---|---|---|---|
JDK-8309865 | 22 | Maurizio Cimadamore | P3 | Resolved | Fixed | b02 |
Specification states:
withElementCountCopy SequenceLayout withElementCount(long elementCount)
Throws: IllegalArgumentException - if elementCount < 0.
Found:
withElementCount doesn't throw IAE if "long" overflow happens.
The method should be fully documented i.e. AE should be either mentioned or wrapped.
jshell> SequenceLayout sl = MemoryLayout.sequenceLayout(4, MemoryLayout.sequenceLayout(4,ValueLayout.JAVA_LONG));
sl ==> [4:[4:j64]]
jshell> sl.withElementCount(Long.MIN_VALUE/(7*32));
| Exception java.lang.ArithmeticException: long overflow
| at Math.multiplyExact (Math.java:1032)
| at SequenceLayoutImpl.<init> (SequenceLayoutImpl.java:43)
| at SequenceLayoutImpl.withElementCount (SequenceLayoutImpl.java:71)
| at (#31:1)
also it would be good to wrap ArithmeticException: long overflow in IAE for positive counts:
jshell> sl.withElementCount(Long.MAX_VALUE/(7*32));
| Exception java.lang.ArithmeticException: long overflow
| at Math.multiplyExact (Math.java:1032)
| at SequenceLayoutImpl.<init> (SequenceLayoutImpl.java:43)
| at SequenceLayoutImpl.withElementCount (SequenceLayoutImpl.java:71)
| at (#34:1)
withElementCountCopy SequenceLayout withElementCount(long elementCount)
Throws: IllegalArgumentException - if elementCount < 0.
Found:
withElementCount doesn't throw IAE if "long" overflow happens.
The method should be fully documented i.e. AE should be either mentioned or wrapped.
jshell> SequenceLayout sl = MemoryLayout.sequenceLayout(4, MemoryLayout.sequenceLayout(4,ValueLayout.JAVA_LONG));
sl ==> [4:[4:j64]]
jshell> sl.withElementCount(Long.MIN_VALUE/(7*32));
| Exception java.lang.ArithmeticException: long overflow
| at Math.multiplyExact (Math.java:1032)
| at SequenceLayoutImpl.<init> (SequenceLayoutImpl.java:43)
| at SequenceLayoutImpl.withElementCount (SequenceLayoutImpl.java:71)
| at (#31:1)
also it would be good to wrap ArithmeticException: long overflow in IAE for positive counts:
jshell> sl.withElementCount(Long.MAX_VALUE/(7*32));
| Exception java.lang.ArithmeticException: long overflow
| at Math.multiplyExact (Math.java:1032)
| at SequenceLayoutImpl.<init> (SequenceLayoutImpl.java:43)
| at SequenceLayoutImpl.withElementCount (SequenceLayoutImpl.java:71)
| at (#34:1)
- backported by
-
JDK-8309865 SequenceLayout::withElementCount(long elementCount) doesn't throw IllegalArgumentException - if elementCount < 0 for some cases
-
- Resolved
-