diff --git a/java/src/main/java/com/google/protobuf/GeneratedMessage.java b/java/src/main/java/com/google/protobuf/GeneratedMessage.java index 5cff6fc681..42ccbfd86a 100644 --- a/java/src/main/java/com/google/protobuf/GeneratedMessage.java +++ b/java/src/main/java/com/google/protobuf/GeneratedMessage.java @@ -769,7 +769,7 @@ public abstract class GeneratedMessage extends AbstractMessage { /** For use by generated code only. */ public void internalInit(final FieldDescriptor descriptor, - final Class type) { + final Class type) { if (this.descriptor != null) { throw new IllegalStateException("Already initialized."); } @@ -809,7 +809,7 @@ public abstract class GeneratedMessage extends AbstractMessage { } private FieldDescriptor descriptor; - private Class type; + private Class type; private Method enumValueOf; private Method enumGetValueDescriptor; private Message messageDefaultInstance; @@ -1054,7 +1054,7 @@ public abstract class GeneratedMessage extends AbstractMessage { // Note: We use Java reflection to call public methods rather than // access private fields directly as this avoids runtime security // checks. - protected final Class type; + protected final Class type; protected final Method getMethod; protected final Method setMethod; protected final Method hasMethod; @@ -1118,7 +1118,7 @@ public abstract class GeneratedMessage extends AbstractMessage { clearMethod = getMethodOrDie(builderClass, "clear" + camelCaseName); } - protected final Class type; + protected final Class type; protected final Method getMethod; protected final Method getRepeatedMethod; protected final Method setRepeatedMethod; diff --git a/java/src/main/java/com/google/protobuf/GeneratedMessageLite.java b/java/src/main/java/com/google/protobuf/GeneratedMessageLite.java index 9cdd4e94d1..9a799b44c6 100644 --- a/java/src/main/java/com/google/protobuf/GeneratedMessageLite.java +++ b/java/src/main/java/com/google/protobuf/GeneratedMessageLite.java @@ -524,6 +524,7 @@ public abstract class GeneratedMessageLite extends AbstractMessageLite { } /** For use by generated code only. */ + @SuppressWarnings("unchecked") public void internalInitRepeated( final ContainingType containingTypeDefaultInstance, final MessageLite messageDefaultInstance, diff --git a/java/src/test/java/com/google/protobuf/DescriptorsTest.java b/java/src/test/java/com/google/protobuf/DescriptorsTest.java index e60eab39da..c77af5d251 100644 --- a/java/src/test/java/com/google/protobuf/DescriptorsTest.java +++ b/java/src/test/java/com/google/protobuf/DescriptorsTest.java @@ -70,6 +70,7 @@ public class DescriptorsTest extends TestCase { // Regression test for bug where referencing a FieldDescriptor.Type value // before a FieldDescriptorProto.Type value would yield a // ExceptionInInitializerError. + @SuppressWarnings("unused") private static final Object STATIC_INIT_TEST = FieldDescriptor.Type.BOOL; public void testFieldTypeEnumMapping() throws Exception { diff --git a/src/google/protobuf/compiler/java/java_enum.cc b/src/google/protobuf/compiler/java/java_enum.cc index 85e39f5317..e796587f4e 100644 --- a/src/google/protobuf/compiler/java/java_enum.cc +++ b/src/google/protobuf/compiler/java/java_enum.cc @@ -138,7 +138,7 @@ void EnumGenerator::Generate(io::Printer* printer) { " internalValueMap =\n" " new com.google.protobuf.Internal.EnumLiteMap<$classname$>() {\n" " public $classname$ findValueByNumber(int number) {\n" - " return $classname$.valueOf(number)\n;" + " return $classname$.valueOf(number);\n" " }\n" " };\n" "\n", @@ -190,6 +190,7 @@ void EnumGenerator::Generate(io::Printer* printer) { printer->Print( "\n" "};\n" + "\n" "public static $classname$ valueOf(\n" " com.google.protobuf.Descriptors.EnumValueDescriptor desc) {\n" " if (desc.getType() != getDescriptor()) {\n" @@ -197,20 +198,26 @@ void EnumGenerator::Generate(io::Printer* printer) { " \"EnumValueDescriptor is not for this type.\");\n" " }\n" " return VALUES[desc.getIndex()];\n" - "}\n", + "}\n" + "\n", "classname", descriptor_->name()); + + // index is only used for reflection; lite implementation does not need it + printer->Print("private final int index;\n"); } // ----------------------------------------------------------------- printer->Print( - "private final int index;\n" - "private final int value;\n" - "private $classname$(int index, int value) {\n" - " this.index = index;\n" - " this.value = value;\n" - "}\n", + "private final int value;\n\n" + "private $classname$(int index, int value) {\n", "classname", descriptor_->name()); + if (HasDescriptorMethods(descriptor_)) { + printer->Print(" this.index = index;\n"); + } + printer->Print( + " this.value = value;\n" + "}\n"); if (HasDescriptorMethods(descriptor_)) { // Force the static initialization code for the file to run, since it may diff --git a/src/google/protobuf/compiler/java/java_message.cc b/src/google/protobuf/compiler/java/java_message.cc index a326057176..8b91193fcb 100644 --- a/src/google/protobuf/compiler/java/java_message.cc +++ b/src/google/protobuf/compiler/java/java_message.cc @@ -420,15 +420,18 @@ GenerateMessageSerializationMethods(io::Printer* printer) { if (descriptor_->extension_range_count() > 0) { if (descriptor_->options().message_set_wire_format()) { printer->Print( - "com.google.protobuf.GeneratedMessage$lite$.ExtendableMessage\n" - " .ExtensionWriter extensionWriter =\n" + "com.google.protobuf.GeneratedMessage$lite$\n" + " .ExtendableMessage<$classname$>.ExtensionWriter extensionWriter =\n" " newMessageSetExtensionWriter();\n", - "lite", HasDescriptorMethods(descriptor_) ? "" : "Lite"); + "lite", HasDescriptorMethods(descriptor_) ? "" : "Lite", + "classname", ClassName(descriptor_)); } else { printer->Print( - "com.google.protobuf.GeneratedMessage$lite$.ExtendableMessage\n" - " .ExtensionWriter extensionWriter = newExtensionWriter();\n", - "lite", HasDescriptorMethods(descriptor_) ? "" : "Lite"); + "com.google.protobuf.GeneratedMessage$lite$\n" + " .ExtendableMessage<$classname$>.ExtensionWriter extensionWriter =\n" + " newExtensionWriter();\n", + "lite", HasDescriptorMethods(descriptor_) ? "" : "Lite", + "classname", ClassName(descriptor_)); } }