Skip to content

Commit

Permalink
Make type conversions explicit. (google#7595)
Browse files Browse the repository at this point in the history
As Java does not support unsigned integer types, the value types
are "rounded up" (an uint32 is represented as a long) but persisted
correctly (an uint32 is persisted as 4 bytes).

This CL makes a cast operation explicit so that the compiler
does not throw warning messages.

Co-authored-by: Dominic Battre <battre@chromium.org>
Co-authored-by: Derek Bailey <derekbailey@google.com>
  • Loading branch information
3 people authored and bulentv committed Oct 21, 2022
1 parent 546839d commit d4f6d4e
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
1 change: 0 additions & 1 deletion java/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@
<release>8</release>
<testExcludes>
<testExclude>MyGame/Example/MonsterStorageGrpc.java</testExclude>
<testExclude>MyGame/Example/StructOfStructs**</testExclude>
<testExclude>MyGame/OtherNameSpace/TableBT.java</testExclude>
</testExcludes>
</configuration>
Expand Down
1 change: 1 addition & 0 deletions src/idl_gen_java.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1893,6 +1893,7 @@ class JavaGenerator : public BaseGenerator {
}
} else {
code += " " + name + " = ";
code += SourceCast(field_type);
code += "_o";
for (size_t i = 0; i < array_lengths.size(); ++i) {
code += "." + namer_.Method("get", array_lengths[i].name) + "()";
Expand Down
8 changes: 4 additions & 4 deletions tests/MyGame/Example/StructOfStructs.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,12 @@ public void unpackTo(StructOfStructsT _o) {
}
public static int pack(FlatBufferBuilder builder, StructOfStructsT _o) {
if (_o == null) return 0;
int _a_id = _o.getA().getId();
int _a_distance = _o.getA().getDistance();
int _a_id = (int) _o.getA().getId();
int _a_distance = (int) _o.getA().getDistance();
short _b_a = _o.getB().getA();
byte _b_b = _o.getB().getB();
int _c_id = _o.getC().getId();
int _c_distance = _o.getC().getDistance();
int _c_id = (int) _o.getC().getId();
int _c_distance = (int) _o.getC().getDistance();
return createStructOfStructs(
builder,
_a_id,
Expand Down
8 changes: 4 additions & 4 deletions tests/MyGame/Example/StructOfStructsOfStructs.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@ public void unpackTo(StructOfStructsOfStructsT _o) {
}
public static int pack(FlatBufferBuilder builder, StructOfStructsOfStructsT _o) {
if (_o == null) return 0;
int _a_a_id = _o.getA().getA().getId();
int _a_a_distance = _o.getA().getA().getDistance();
int _a_a_id = (int) _o.getA().getA().getId();
int _a_a_distance = (int) _o.getA().getA().getDistance();
short _a_b_a = _o.getA().getB().getA();
byte _a_b_b = _o.getA().getB().getB();
int _a_c_id = _o.getA().getC().getId();
int _a_c_distance = _o.getA().getC().getDistance();
int _a_c_id = (int) _o.getA().getC().getId();
int _a_c_distance = (int) _o.getA().getC().getDistance();
return createStructOfStructsOfStructs(
builder,
_a_a_id,
Expand Down

0 comments on commit d4f6d4e

Please sign in to comment.