[Java] generation for unsinged integers - #24764
Conversation
There was a problem hiding this comment.
All reported issues were addressed across 2 files
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
There was a problem hiding this comment.
1 issue found and verified against the latest diff
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractJavaCodegen.java">
<violation number="1" location="modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractJavaCodegen.java:1980">
P2: For a one-sided integer range, the missing side is unbounded, so `Integer` or `Long` cannot represent every allowed value. Return `BigInteger` whenever either bound is absent, or otherwise evaluate both finite bounds.</violation>
</file>
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
| if (Optional.ofNullable(minimum).map(this::fitsInInt).orElse(true) | ||
| && Optional.ofNullable(maximum).map(this::fitsInInt).orElse(true)) { | ||
| return typeMapping.get("integer"); | ||
| } else if (Optional.ofNullable(minimum).map(this::fitsInLong).orElse(true) | ||
| && Optional.ofNullable(maximum).map(this::fitsInLong).orElse(true)) { | ||
| return typeMapping.get("long"); | ||
| } | ||
| return typeMapping.get("BigInteger"); |
There was a problem hiding this comment.
P2: For a one-sided integer range, the missing side is unbounded, so Integer or Long cannot represent every allowed value. Return BigInteger whenever either bound is absent, or otherwise evaluate both finite bounds.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractJavaCodegen.java, line 1980:
<comment>For a one-sided integer range, the missing side is unbounded, so `Integer` or `Long` cannot represent every allowed value. Return `BigInteger` whenever either bound is absent, or otherwise evaluate both finite bounds.</comment>
<file context>
@@ -1922,6 +1959,92 @@ public String getSchemaType(Schema p) {
+ maximum = maximum.subtract(BigDecimal.ONE);
+ }
+
+ if (Optional.ofNullable(minimum).map(this::fitsInInt).orElse(true)
+ && Optional.ofNullable(maximum).map(this::fitsInInt).orElse(true)) {
+ return typeMapping.get("integer");
</file context>
| if (Optional.ofNullable(minimum).map(this::fitsInInt).orElse(true) | |
| && Optional.ofNullable(maximum).map(this::fitsInInt).orElse(true)) { | |
| return typeMapping.get("integer"); | |
| } else if (Optional.ofNullable(minimum).map(this::fitsInLong).orElse(true) | |
| && Optional.ofNullable(maximum).map(this::fitsInLong).orElse(true)) { | |
| return typeMapping.get("long"); | |
| } | |
| return typeMapping.get("BigInteger"); | |
| if (minimum == null || maximum == null) { | |
| return typeMapping.get("BigInteger"); | |
| } else if (fitsInInt(minimum) && fitsInInt(maximum)) { | |
| return typeMapping.get("integer"); | |
| } else if (fitsInLong(minimum) && fitsInLong(maximum)) { | |
| return typeMapping.get("long"); | |
| } | |
| return typeMapping.get("BigInteger"); |
There was a problem hiding this comment.
wouldn't that mean that every integer without a range that was previously generated as Integer, now would be generated as BigInteger and breaking the generated API usage?
fix #11087
ensure that integer with a given unsigned format (uint32/uint64) or with a given range, get generated with a type that covers their range.
uint32 will be generated as long
uint64 will be generated as BigInteger
ranges will be recognized and fitting data type is chosen depending on minimum/maximun
PR checklist
Commit all changed files.
This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master.
These must match the expectations made by your contribution.
You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example
./bin/generate-samples.sh bin/configs/java*.IMPORTANT: Do NOT purge/delete any folders/files (e.g. tests) when regenerating the samples as manually written tests may be removed.
Java | @bbdouglas (2017/07) @sreeshas (2017/08) @jfiala (2017/08) @lukoyanov (2017/09) @cbornet (2017/09) @jeff9finger (2018/01) @karismann (2019/03) @Zomzog (2019/04) @lwlee2608 (2019/10) @martin-mfg (2023/08) @KannaKim (2026/07)
Summary by cubic
Generates Java types that cover unsigned and bounded integer schemas to prevent overflow. Previously
uint32/uint64and range-limited integers defaulted to signedInteger/Long; now the generator widens toLongorBigIntegerbased on format or bounds, honoring exclusive limits.Maps
uint32toLonganduint64toBigInteger; standardint32/int64remainInteger/Long.Infers the smallest of
Integer/Long/BigIntegerwhen min/max are set (honors exclusive bounds).Adds
BigIntegertotypeMappingandimportMapping, and importsjava.math.BigInteger; applies toJavaDubboServerCodegen.Keeps
isInteger/isLongflags consistent for properties and parameters with widened types; tests cover format and range inference.Migration
IntegertoLongorBigInteger. Update consumers and serializers to acceptLong/BigInteger.Written for commit 95030c0. Summary will update on new commits.