Previously, extensions with field numbers greater than 268435455 would result in a compile time error in generated code that looks something like this: Foo.java:3178: error: integer number too large: 3346754610 3346754610); This is because we were trying to represent the tag number (an unsigned int) using a java int constant, but java int constants are signed, and can't exceed Integer.MAX_VALUE. Fixed by declaring it as a long instead, and casting it down to an int in the implementation. This is safe, because the tag value always fits in 32 bis. Change-Id: If2017bacb4e20af667eaeaf9b65ddc2c30a7709fpull/315/head
parent
fe7b5667eb
commit
ec2f244554
4 changed files with 31 additions and 9 deletions
@ -0,0 +1,13 @@ |
||||
diff a/javanano/src/main/java/com/google/protobuf/nano/Extension.java b/javanano/src/main/java/com/google/protobuf/nano/Extension.java (rejected hunks) |
||||
@@ -74,6 +74,11 @@ public class Extension<M extends ExtendableMessageNano<M>, T> { |
||||
public static final int TYPE_SINT32 = 17; |
||||
public static final int TYPE_SINT64 = 18; |
||||
|
||||
+ // Note: these create...() methods take a long for the tag parameter, |
||||
+ // because tags are represented as unsigned longs, and these values exist |
||||
+ // in generated code as long values. However, they can fit in 32-bits, so |
||||
+ // it's safe to cast them to int without loss of precision. |
||||
+ |
||||
/** |
||||
* Creates an {@code Extension} of the given message type and tag number. |
||||
* Should be used by the generated code only. |
Loading…
Reference in new issue