aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkenton@google.com <kenton@google.com@630680e5-0e50-0410-840e-4b1c322b438d>2010-01-21 22:10:55 +0000
committerkenton@google.com <kenton@google.com@630680e5-0e50-0410-840e-4b1c322b438d>2010-01-21 22:10:55 +0000
commit28c2ec0dbdd6f1b0ea844f1ccce6c8f05ae917e8 (patch)
treec4ff9f2230ba3852b3d4967dd15c477112d8adde
parent48443683465c7fc85eb6d2d8174c0f481fcf90c9 (diff)
downloadprotobuf-28c2ec0dbdd6f1b0ea844f1ccce6c8f05ae917e8.tar.gz
protobuf-28c2ec0dbdd6f1b0ea844f1ccce6c8f05ae917e8.tar.bz2
protobuf-28c2ec0dbdd6f1b0ea844f1ccce6c8f05ae917e8.zip
Fix some Java warnings. Patch from Evan Jones.
-rw-r--r--CONTRIBUTORS.txt1
-rw-r--r--java/src/main/java/com/google/protobuf/AbstractMessage.java1
-rw-r--r--java/src/main/java/com/google/protobuf/AbstractMessageLite.java3
-rw-r--r--java/src/main/java/com/google/protobuf/FieldSet.java10
-rw-r--r--java/src/main/java/com/google/protobuf/GeneratedMessage.java6
-rw-r--r--java/src/main/java/com/google/protobuf/TextFormat.java3
-rw-r--r--java/src/test/java/com/google/protobuf/CodedOutputStreamTest.java1
-rw-r--r--java/src/test/java/com/google/protobuf/DescriptorsTest.java1
-rw-r--r--java/src/test/java/com/google/protobuf/ServiceTest.java6
-rw-r--r--java/src/test/java/com/google/protobuf/TextFormatTest.java8
10 files changed, 16 insertions, 24 deletions
diff --git a/CONTRIBUTORS.txt b/CONTRIBUTORS.txt
index a20efc4b..6c002af9 100644
--- a/CONTRIBUTORS.txt
+++ b/CONTRIBUTORS.txt
@@ -80,5 +80,6 @@ Patch contributors:
* 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().
diff --git a/java/src/main/java/com/google/protobuf/AbstractMessage.java b/java/src/main/java/com/google/protobuf/AbstractMessage.java
index b059bc98..fb416bdc 100644
--- a/java/src/main/java/com/google/protobuf/AbstractMessage.java
+++ b/java/src/main/java/com/google/protobuf/AbstractMessage.java
@@ -274,7 +274,6 @@ public abstract class AbstractMessage extends AbstractMessageLite
* @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,
diff --git a/java/src/main/java/com/google/protobuf/AbstractMessageLite.java b/java/src/main/java/com/google/protobuf/AbstractMessageLite.java
index 9210d853..77b27370 100644
--- a/java/src/main/java/com/google/protobuf/AbstractMessageLite.java
+++ b/java/src/main/java/com/google/protobuf/AbstractMessageLite.java
@@ -313,8 +313,7 @@ public abstract class AbstractMessageLite implements MessageLite {
}
}
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) {
diff --git a/java/src/main/java/com/google/protobuf/FieldSet.java b/java/src/main/java/com/google/protobuf/FieldSet.java
index 93e55f29..bc1bb797 100644
--- a/java/src/main/java/com/google/protobuf/FieldSet.java
+++ b/java/src/main/java/com/google/protobuf/FieldSet.java
@@ -210,7 +210,7 @@ final class FieldSet<FieldDescriptorType extends
if (value == null) {
return 0;
} else {
- return ((List) value).size();
+ return ((List<?>) value).size();
}
}
@@ -230,7 +230,7 @@ final class FieldSet<FieldDescriptorType extends
if (value == null) {
throw new IndexOutOfBoundsException();
} else {
- return ((List) value).get(index);
+ return ((List<?>) value).get(index);
}
}
@@ -564,7 +564,7 @@ final class FieldSet<FieldDescriptorType extends
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.
@@ -692,7 +692,7 @@ final class FieldSet<FieldDescriptorType extends
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 +
@@ -700,7 +700,7 @@ final class FieldSet<FieldDescriptorType extends
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;
diff --git a/java/src/main/java/com/google/protobuf/GeneratedMessage.java b/java/src/main/java/com/google/protobuf/GeneratedMessage.java
index dba0ec83..5cff6fc6 100644
--- a/java/src/main/java/com/google/protobuf/GeneratedMessage.java
+++ b/java/src/main/java/com/google/protobuf/GeneratedMessage.java
@@ -75,7 +75,7 @@ public abstract class GeneratedMessage extends AbstractMessage {
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);
}
@@ -652,7 +652,6 @@ public abstract class GeneratedMessage extends AbstractMessage {
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);
}
@@ -821,7 +820,6 @@ public abstract class GeneratedMessage extends AbstractMessage {
* If the extension is an embedded message or group, returns the default
* instance of the message.
*/
- @SuppressWarnings("unchecked")
public Message getMessageDefaultInstance() {
return messageDefaultInstance;
}
@@ -1137,7 +1135,7 @@ public abstract class GeneratedMessage extends AbstractMessage {
// 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);
}
}
diff --git a/java/src/main/java/com/google/protobuf/TextFormat.java b/java/src/main/java/com/google/protobuf/TextFormat.java
index cb23f0c3..7ca2b4bf 100644
--- a/java/src/main/java/com/google/protobuf/TextFormat.java
+++ b/java/src/main/java/com/google/protobuf/TextFormat.java
@@ -144,7 +144,7 @@ public final class TextFormat {
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 {
@@ -250,7 +250,6 @@ public final class TextFormat {
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()) {
diff --git a/java/src/test/java/com/google/protobuf/CodedOutputStreamTest.java b/java/src/test/java/com/google/protobuf/CodedOutputStreamTest.java
index c42b485c..48e54657 100644
--- a/java/src/test/java/com/google/protobuf/CodedOutputStreamTest.java
+++ b/java/src/test/java/com/google/protobuf/CodedOutputStreamTest.java
@@ -37,7 +37,6 @@ import junit.framework.TestCase;
import java.io.ByteArrayOutputStream;
import java.util.ArrayList;
-import java.util.Arrays;
import java.util.List;
/**
diff --git a/java/src/test/java/com/google/protobuf/DescriptorsTest.java b/java/src/test/java/com/google/protobuf/DescriptorsTest.java
index f41d070e..e60eab39 100644
--- a/java/src/test/java/com/google/protobuf/DescriptorsTest.java
+++ b/java/src/test/java/com/google/protobuf/DescriptorsTest.java
@@ -44,7 +44,6 @@ import com.google.protobuf.Descriptors.MethodDescriptor;
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;
diff --git a/java/src/test/java/com/google/protobuf/ServiceTest.java b/java/src/test/java/com/google/protobuf/ServiceTest.java
index e10322dc..802eb0e0 100644
--- a/java/src/test/java/com/google/protobuf/ServiceTest.java
+++ b/java/src/test/java/com/google/protobuf/ServiceTest.java
@@ -205,12 +205,6 @@ public class ServiceTest extends TestCase {
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)))
diff --git a/java/src/test/java/com/google/protobuf/TextFormatTest.java b/java/src/test/java/com/google/protobuf/TextFormatTest.java
index 60bd800e..ad48157a 100644
--- a/java/src/test/java/com/google/protobuf/TextFormatTest.java
+++ b/java/src/test/java/com/google/protobuf/TextFormatTest.java
@@ -60,8 +60,8 @@ public class TextFormatTest extends TestCase {
// 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");
@@ -469,6 +469,10 @@ public class TextFormatTest extends TestCase {
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"));