Commit a1bb147e authored by Jisi Liu's avatar Jisi Liu Committed by GitHub

Merge pull request #2825 from pherl/javawarning

Cherry-pick changes from javalite branch to also fix Java warnings in the master branch
parents da003550 009e491b
...@@ -854,6 +854,7 @@ public abstract class GeneratedMessage extends AbstractMessage ...@@ -854,6 +854,7 @@ public abstract class GeneratedMessage extends AbstractMessage
/** Check if a singular extension is present. */ /** Check if a singular extension is present. */
@Override @Override
@SuppressWarnings("unchecked")
public final <Type> boolean hasExtension(final ExtensionLite<MessageType, Type> extensionLite) { public final <Type> boolean hasExtension(final ExtensionLite<MessageType, Type> extensionLite) {
Extension<MessageType, Type> extension = checkNotLite(extensionLite); Extension<MessageType, Type> extension = checkNotLite(extensionLite);
...@@ -863,6 +864,7 @@ public abstract class GeneratedMessage extends AbstractMessage ...@@ -863,6 +864,7 @@ public abstract class GeneratedMessage extends AbstractMessage
/** Get the number of elements in a repeated extension. */ /** Get the number of elements in a repeated extension. */
@Override @Override
@SuppressWarnings("unchecked")
public final <Type> int getExtensionCount( public final <Type> int getExtensionCount(
final ExtensionLite<MessageType, List<Type>> extensionLite) { final ExtensionLite<MessageType, List<Type>> extensionLite) {
Extension<MessageType, List<Type>> extension = checkNotLite(extensionLite); Extension<MessageType, List<Type>> extension = checkNotLite(extensionLite);
...@@ -2555,6 +2557,7 @@ public abstract class GeneratedMessage extends AbstractMessage ...@@ -2555,6 +2557,7 @@ public abstract class GeneratedMessage extends AbstractMessage
} }
@Override @Override
@SuppressWarnings("unchecked")
public Object get(GeneratedMessage message) { public Object get(GeneratedMessage message) {
List result = new ArrayList(); List result = new ArrayList();
for (int i = 0; i < getRepeatedCount(message); i++) { for (int i = 0; i < getRepeatedCount(message); i++) {
...@@ -2564,6 +2567,7 @@ public abstract class GeneratedMessage extends AbstractMessage ...@@ -2564,6 +2567,7 @@ public abstract class GeneratedMessage extends AbstractMessage
} }
@Override @Override
@SuppressWarnings("unchecked")
public Object get(Builder builder) { public Object get(Builder builder) {
List result = new ArrayList(); List result = new ArrayList();
for (int i = 0; i < getRepeatedCount(builder); i++) { for (int i = 0; i < getRepeatedCount(builder); i++) {
......
...@@ -220,6 +220,7 @@ public abstract class GeneratedMessageLite< ...@@ -220,6 +220,7 @@ public abstract class GeneratedMessageLite<
} }
@Override @Override
@SuppressWarnings("unchecked")
public final BuilderType toBuilder() { public final BuilderType toBuilder() {
BuilderType builder = (BuilderType) dynamicMethod(MethodToInvoke.NEW_BUILDER); BuilderType builder = (BuilderType) dynamicMethod(MethodToInvoke.NEW_BUILDER);
builder.mergeFrom((MessageType) this); builder.mergeFrom((MessageType) this);
...@@ -453,6 +454,7 @@ public abstract class GeneratedMessageLite< ...@@ -453,6 +454,7 @@ public abstract class GeneratedMessageLite<
*/ */
protected FieldSet<ExtensionDescriptor> extensions = FieldSet.newFieldSet(); protected FieldSet<ExtensionDescriptor> extensions = FieldSet.newFieldSet();
@SuppressWarnings("unchecked")
protected final void mergeExtensionFields(final MessageType other) { protected final void mergeExtensionFields(final MessageType other) {
if (extensions.isImmutable()) { if (extensions.isImmutable()) {
extensions = extensions.clone(); extensions = extensions.clone();
......
...@@ -866,6 +866,7 @@ public abstract class GeneratedMessageV3 extends AbstractMessage ...@@ -866,6 +866,7 @@ public abstract class GeneratedMessageV3 extends AbstractMessage
/** Check if a singular extension is present. */ /** Check if a singular extension is present. */
@Override @Override
@SuppressWarnings("unchecked")
public final <Type> boolean hasExtension(final ExtensionLite<MessageType, Type> extensionLite) { public final <Type> boolean hasExtension(final ExtensionLite<MessageType, Type> extensionLite) {
Extension<MessageType, Type> extension = checkNotLite(extensionLite); Extension<MessageType, Type> extension = checkNotLite(extensionLite);
...@@ -875,6 +876,7 @@ public abstract class GeneratedMessageV3 extends AbstractMessage ...@@ -875,6 +876,7 @@ public abstract class GeneratedMessageV3 extends AbstractMessage
/** Get the number of elements in a repeated extension. */ /** Get the number of elements in a repeated extension. */
@Override @Override
@SuppressWarnings("unchecked")
public final <Type> int getExtensionCount( public final <Type> int getExtensionCount(
final ExtensionLite<MessageType, List<Type>> extensionLite) { final ExtensionLite<MessageType, List<Type>> extensionLite) {
Extension<MessageType, List<Type>> extension = checkNotLite(extensionLite); Extension<MessageType, List<Type>> extension = checkNotLite(extensionLite);
...@@ -2219,6 +2221,7 @@ public abstract class GeneratedMessageV3 extends AbstractMessage ...@@ -2219,6 +2221,7 @@ public abstract class GeneratedMessageV3 extends AbstractMessage
} }
@Override @Override
@SuppressWarnings("unchecked")
public Object get(GeneratedMessageV3 message) { public Object get(GeneratedMessageV3 message) {
List result = new ArrayList(); List result = new ArrayList();
for (int i = 0; i < getRepeatedCount(message); i++) { for (int i = 0; i < getRepeatedCount(message); i++) {
...@@ -2228,6 +2231,7 @@ public abstract class GeneratedMessageV3 extends AbstractMessage ...@@ -2228,6 +2231,7 @@ public abstract class GeneratedMessageV3 extends AbstractMessage
} }
@Override @Override
@SuppressWarnings("unchecked")
public Object get(Builder builder) { public Object get(Builder builder) {
List result = new ArrayList(); List result = new ArrayList();
for (int i = 0; i < getRepeatedCount(builder); i++) { for (int i = 0; i < getRepeatedCount(builder); i++) {
......
...@@ -89,6 +89,7 @@ public final class MapEntry<K, V> extends AbstractMessage { ...@@ -89,6 +89,7 @@ public final class MapEntry<K, V> extends AbstractMessage {
} }
/** Create a MapEntry with the provided key and value. */ /** Create a MapEntry with the provided key and value. */
@SuppressWarnings("unchecked")
private MapEntry(Metadata metadata, K key, V value) { private MapEntry(Metadata metadata, K key, V value) {
this.key = key; this.key = key;
this.value = value; this.value = value;
...@@ -435,6 +436,7 @@ public final class MapEntry<K, V> extends AbstractMessage { ...@@ -435,6 +436,7 @@ public final class MapEntry<K, V> extends AbstractMessage {
} }
@Override @Override
@SuppressWarnings("unchecked")
public Builder<K, V> clone() { public Builder<K, V> clone() {
return new Builder(metadata, key, value); return new Builder(metadata, key, value);
} }
......
...@@ -100,6 +100,7 @@ public class MapField<K, V> implements MutabilityOracle { ...@@ -100,6 +100,7 @@ public class MapField<K, V> implements MutabilityOracle {
} }
@Override @Override
@SuppressWarnings("unchecked")
public void convertMessageToKeyAndValue(Message message, Map<K, V> map) { public void convertMessageToKeyAndValue(Message message, Map<K, V> map) {
MapEntry<K, V> entry = (MapEntry<K, V>) message; MapEntry<K, V> entry = (MapEntry<K, V>) message;
map.put(entry.getKey(), entry.getValue()); map.put(entry.getKey(), entry.getValue());
......
...@@ -1453,6 +1453,7 @@ void ImmutableMessageGenerator::GenerateAnyMethods(io::Printer* printer) { ...@@ -1453,6 +1453,7 @@ void ImmutableMessageGenerator::GenerateAnyMethods(io::Printer* printer) {
"\n" "\n"
"private volatile com.google.protobuf.Message cachedUnpackValue;\n" "private volatile com.google.protobuf.Message cachedUnpackValue;\n"
"\n" "\n"
"@java.lang.SuppressWarnings(\"unchecked\")\n"
"public <T extends com.google.protobuf.Message> T unpack(\n" "public <T extends com.google.protobuf.Message> T unpack(\n"
" java.lang.Class<T> clazz)\n" " java.lang.Class<T> clazz)\n"
" throws com.google.protobuf.InvalidProtocolBufferException {\n" " throws com.google.protobuf.InvalidProtocolBufferException {\n"
......
...@@ -345,6 +345,7 @@ void ImmutableMessageLiteGenerator::Generate(io::Printer* printer) { ...@@ -345,6 +345,7 @@ void ImmutableMessageLiteGenerator::Generate(io::Printer* printer) {
} }
printer->Print( printer->Print(
"@java.lang.SuppressWarnings(\"unchecked\")\n"
"protected final Object dynamicMethod(\n" "protected final Object dynamicMethod(\n"
" com.google.protobuf.GeneratedMessageLite.MethodToInvoke method,\n" " com.google.protobuf.GeneratedMessageLite.MethodToInvoke method,\n"
" Object arg0, Object arg1) {\n" " Object arg0, Object arg1) {\n"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment