Commits

ken...@google.com@630680e5-0e50-0410-840e-4b1c322b438d  committed 35a4005

Fix some Java warnings. Patch from Evan Jones.

  • Participants
  • Parent commits 44f55ee

Comments (0)

Files changed (10)

File CONTRIBUTORS.txt

     * Fixes for Solaris 10 32/64-bit confusion.
   Evan Jones <evanj@mit.edu>
     * Optimize Java serialization code when writing a small message to a stream.
+    * Clean up some Java warnings.
   Michael Kucharski <m.kucharski@gmail.com>
     * Added CodedInputStream.getTotalBytesRead().

File java/src/main/java/com/google/protobuf/AbstractMessage.java

      * @param tag The tag, which should have already been read.
      * @return {@code true} unless the tag is an end-group tag.
      */
-    @SuppressWarnings("unchecked")
     static boolean mergeFieldFrom(
         final CodedInputStream input,
         final UnknownFieldSet.Builder unknownFields,

File java/src/main/java/com/google/protobuf/AbstractMessageLite.java

         }
       }
       if (values instanceof Collection) {
-        @SuppressWarnings("unsafe") final
-        Collection<T> collection = (Collection<T>) values;
+        final Collection<T> collection = (Collection<T>) values;
         list.addAll(collection);
       } else {
         for (final T value : values) {

File java/src/main/java/com/google/protobuf/FieldSet.java

     if (value == null) {
       return 0;
     } else {
-      return ((List) value).size();
+      return ((List<?>) value).size();
     }
   }
 
     if (value == null) {
       throw new IndexOutOfBoundsException();
     } else {
-      return ((List) value).get(index);
+      return ((List<?>) value).get(index);
     }
   }
 
     WireFormat.FieldType type = descriptor.getLiteType();
     int number = descriptor.getNumber();
     if (descriptor.isRepeated()) {
-      final List valueList = (List)value;
+      final List<?> valueList = (List<?>)value;
       if (descriptor.isPacked()) {
         output.writeTag(number, WireFormat.WIRETYPE_LENGTH_DELIMITED);
         // Compute the total data size so the length can be written.
     if (descriptor.isRepeated()) {
       if (descriptor.isPacked()) {
         int dataSize = 0;
-        for (final Object element : (List)value) {
+        for (final Object element : (List<?>)value) {
           dataSize += computeElementSizeNoTag(type, element);
         }
         return dataSize +
             CodedOutputStream.computeRawVarint32Size(dataSize);
       } else {
         int size = 0;
-        for (final Object element : (List)value) {
+        for (final Object element : (List<?>)value) {
           size += computeElementSize(type, number, element);
         }
         return size;

File java/src/main/java/com/google/protobuf/GeneratedMessage.java

     final Descriptor descriptor = internalGetFieldAccessorTable().descriptor;
     for (final FieldDescriptor field : descriptor.getFields()) {
       if (field.isRepeated()) {
-        final List value = (List) getField(field);
+        final List<?> value = (List<?>) getField(field);
         if (!value.isEmpty()) {
           result.put(field, value);
         }
         final UnknownFieldSet.Builder unknownFields,
         final ExtensionRegistryLite extensionRegistry,
         final int tag) throws IOException {
-      final ExtendableMessage<MessageType> message = internalGetResult();
       return AbstractMessage.Builder.mergeFieldFrom(
         input, unknownFields, extensionRegistry, this, tag);
     }
      * If the extension is an embedded message or group, returns the default
      * instance of the message.
      */
-    @SuppressWarnings("unchecked")
     public Message getMessageDefaultInstance() {
       return messageDefaultInstance;
     }
         // 2) Insures that the caller cannot modify the list later on and
         //    have the modifications be reflected in the message.
         clear(builder);
-        for (final Object element : (List) value) {
+        for (final Object element : (List<?>) value) {
           addRepeated(builder, element);
         }
       }

File java/src/main/java/com/google/protobuf/TextFormat.java

                                 throws IOException {
     if (field.isRepeated()) {
       // Repeated field.  Print each element.
-      for (final Object element : (List) value) {
+      for (final Object element : (List<?>) value) {
         printSingleField(field, element, generator);
       }
     } else {
                                          throws IOException {
     for (final Map.Entry<Integer, UnknownFieldSet.Field> entry :
          unknownFields.asMap().entrySet()) {
-      final String prefix = entry.getKey().toString() + ": ";
       final UnknownFieldSet.Field field = entry.getValue();
 
       for (final long value : field.getVarintList()) {

File java/src/test/java/com/google/protobuf/CodedOutputStreamTest.java

 
 import java.io.ByteArrayOutputStream;
 import java.util.ArrayList;
-import java.util.Arrays;
 import java.util.List;
 
 /**

File java/src/test/java/com/google/protobuf/DescriptorsTest.java

 
 import com.google.protobuf.test.UnittestImport;
 import com.google.protobuf.test.UnittestImport.ImportEnum;
-import com.google.protobuf.test.UnittestImport.ImportMessage;
 import protobuf_unittest.UnittestProto;
 import protobuf_unittest.UnittestProto.ForeignEnum;
 import protobuf_unittest.UnittestProto.ForeignMessage;

File java/src/test/java/com/google/protobuf/ServiceTest.java

     MethodDescriptor fooMethod =
         ServiceWithNoOuter.getDescriptor().findMethodByName("Foo");
     MessageWithNoOuter request = MessageWithNoOuter.getDefaultInstance();
-    RpcCallback<Message> callback = new RpcCallback<Message>() {
-      public void run(Message parameter) {
-        // No reason this should be run.
-        fail();
-      }
-    };
 
     TestAllTypes expectedResponse = TestAllTypes.getDefaultInstance();
     EasyMock.expect(impl.foo(EasyMock.same(controller), EasyMock.same(request)))

File java/src/test/java/com/google/protobuf/TextFormatTest.java

 
   // A representation of the above string with all the characters escaped.
   private final static String kEscapeTestStringEscaped =
-      "\"\\\"A string with \\' characters \\n and \\r newlines "
-          + "and \\t tabs and \\001 slashes \\\\\"";
+      "\\\"A string with \\' characters \\n and \\r newlines "
+          + "and \\t tabs and \\001 slashes \\\\";
 
   private static String allFieldsSetText = TestUtil.readTextFromFile(
     "text_format_unittest_data.txt");
       TextFormat.unescapeBytes("\\000\\001\\a\\b\\f\\n\\r\\t\\v\\\\\\'\\\""));
     assertEquals("\0\001\007\b\f\n\r\t\013\\\'\"",
       TextFormat.unescapeText("\\000\\001\\a\\b\\f\\n\\r\\t\\v\\\\\\'\\\""));
+    assertEquals(kEscapeTestStringEscaped,
+      TextFormat.escapeText(kEscapeTestString));
+    assertEquals(kEscapeTestString,
+      TextFormat.unescapeText(kEscapeTestStringEscaped));
 
     // Unicode handling.
     assertEquals("\\341\\210\\264", TextFormat.escapeText("\u1234"));