Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IllegalFormatWidthException occurs in String.format when running tests in Java17. #1082

Open
btkawaharahd opened this issue May 25, 2021 · 0 comments

Comments

@btkawaharahd
Copy link
Contributor

btkawaharahd commented May 25, 2021

Description

Please write the problem in detail.
Please write based on facts as much as possible, and post links to references/Javadoc or stack traces.

IllegalFormatWidthException occurs in String.format when running mvn-build-all.bat in Java17.

[ERROR] Tests run: 12, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.043 s <<< FAILURE! - in org.terasoluna.gfw.common.validator.constraints.ByteSizeTest
[ERROR] testSpecifyNotSpecifyMinAndMax(org.terasoluna.gfw.common.validator.constraints.ByteSizeTest)  Time elapsed: 0.01 s  <<< ERROR!
java.util.IllegalFormatWidthException: -2147483648
        at org.terasoluna.gfw.common.validator.constraints.ByteSizeTest.testSpecifyNotSpecifyMinAndMax(ByteSizeTest.java:196)


The above error occurs in Java 16 and later.

Possible Solution

Please write ideas or candidates of solutions for the problem if you have.
If it is an example, please enter a description such as "For example".

The following information can be found in the Release Notes for Java 16(http://jdk.java.net/16/release-notes)

Argument Index of Zero or Unrepresentable by int Throws IllegalFormatException. (JDK-8253459)
core-libs/java.util
Format string specifiers now throw exceptions when given values outside of valid ranges of values.
The Formatter class in java.util defines format specifiers such as argument indexes, argument widths, and argument precisions. Numeric values that are invalid (zero for argument index) or too large (beyond the size of an int) could create unexpected results with undefined behavior. This update gives explicit value ranges for these format specifiers. Widths and indexes will be valid from [1, Integer.MAX_VALUE] and precision fields will be valid from [0, Integer.MAX_VALUE]. Values outside of these ranges will result in IllegalFormatException or one of its subclasses being thrown. Note that argument indexes of zero prior to this change did not throw an exception and produced behavior that was undefined, but had the appearance of correctness despite causing side effects that were not obvious.

The above error seems to be caused by setting the first argument of the String.format method to a value that exceeds the size of an int.
If Long.MAX_VALUE is modified to Integer.MAX_VALUE, the above error does not occur, but the following OutOfMemoryError occurs.

[ERROR] Tests run: 12, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 3.832 s <<< FAILURE! - in org.terasoluna.gfw.common.validator.constraints.ByteSizeTest
[ERROR] testSpecifyNotSpecifyMinAndMax(org.terasoluna.gfw.common.validator.constraints.ByteSizeTest)  Time elapsed: 3.78 s  <<< ERROR!
java.lang.OutOfMemoryError: Java heap space
        at org.terasoluna.gfw.common.validator.constraints.ByteSizeTest.testSpecifyNotSpecifyMinAndMax(ByteSizeTest.java:197)

[ERROR] Errors:
[ERROR]   ByteSizeTest.testSpecifyNotSpecifyMinAndMax:197 ≫ OutOfMemory Java heap space

[ERROR] Tests run: 56, Failures: 0, Errors: 1, Skipped: 0

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:3.0.0-M3:test (default-test) on project terasoluna-gfw-validator: There are test failures.

The maximum value of int (Integer.MAX_VALUE) seems to cause insufficient memory.
If Long.MAX_VALUE is modified to 600000000, OutOfMemoryError will not occur and BUILD SUCCESS will occur.

Affect versions

Version in which the problem occurs. Current version if not known.
If there is a feature suggestion, please delete it.

  • 5.x.x.RELEASE

Issue links

Links to related issues.

  • #xx
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant