Breaking change: Remove deprecated runtime methods for compatibility with old v2.x.x gencode.

These methods were deprecated as of 3.0.0 and were originally added for compatibility with gencode from old major versions (v2.x.x.) which are long out of our Cross Version Runtime Guarantees: https://protobuf.dev/support/cross-version-runtime-guarantee/

PiperOrigin-RevId: 587099512
pull/14927/head
Sandy Zhang 1 year ago committed by Copybara-Service
parent dfb8a4c3f7
commit e555bd23d0
  1. 40
      java/core/src/main/java/com/google/protobuf/AbstractMessage.java
  2. 29
      java/core/src/main/java/com/google/protobuf/GeneratedMessageLite.java

@ -538,44 +538,4 @@ public abstract class AbstractMessage
return (BuilderType) super.mergeFrom(input, extensionRegistry); return (BuilderType) super.mergeFrom(input, extensionRegistry);
} }
} }
/**
* @deprecated from v3.0.0-beta-3+, for compatibility with v2.5.0 and v2.6.1
* generated code.
*/
@Deprecated
protected static int hashLong(long n) {
return (int) (n ^ (n >>> 32));
}
/**
* @deprecated from v3.0.0-beta-3+, for compatibility with v2.5.0 and v2.6.1
* generated code.
*/
@Deprecated
protected static int hashBoolean(boolean b) {
return b ? 1231 : 1237;
}
/**
* @deprecated from v3.0.0-beta-3+, for compatibility with v2.5.0 and v2.6.1
* generated code.
*/
@Deprecated
protected static int hashEnum(EnumLite e) {
return e.getNumber();
}
/**
* @deprecated from v3.0.0-beta-3+, for compatibility with v2.5.0 and v2.6.1
* generated code.
*/
@Deprecated
protected static int hashEnumList(List<? extends EnumLite> list) {
int hash = 1;
for (EnumLite e : list) {
hash = 31 * hash + hashEnum(e);
}
return hash;
}
} }

@ -1440,7 +1440,7 @@ public abstract class GeneratedMessageLite<
} catch (ClassNotFoundException e) { } catch (ClassNotFoundException e) {
throw new RuntimeException("Unable to find proto buffer class: " + messageClassName, e); throw new RuntimeException("Unable to find proto buffer class: " + messageClassName, e);
} catch (NoSuchFieldException e) { } catch (NoSuchFieldException e) {
return readResolveFallback(); throw new RuntimeException("Unable to find DEFAULT_INSTANCE in " + messageClassName, e);
} catch (SecurityException e) { } catch (SecurityException e) {
throw new RuntimeException("Unable to call DEFAULT_INSTANCE in " + messageClassName, e); throw new RuntimeException("Unable to call DEFAULT_INSTANCE in " + messageClassName, e);
} catch (IllegalAccessException e) { } catch (IllegalAccessException e) {
@ -1450,33 +1450,6 @@ public abstract class GeneratedMessageLite<
} }
} }
/**
* @deprecated from v3.0.0-beta-3+, for compatibility with v2.5.0 and v2.6.1 generated code.
*/
@Deprecated
private Object readResolveFallback() throws ObjectStreamException {
try {
Class<?> messageClass = resolveMessageClass();
java.lang.reflect.Field defaultInstanceField =
messageClass.getDeclaredField("defaultInstance");
defaultInstanceField.setAccessible(true);
MessageLite defaultInstance = (MessageLite) defaultInstanceField.get(null);
return defaultInstance.newBuilderForType()
.mergeFrom(asBytes)
.buildPartial();
} catch (ClassNotFoundException e) {
throw new RuntimeException("Unable to find proto buffer class: " + messageClassName, e);
} catch (NoSuchFieldException e) {
throw new RuntimeException("Unable to find defaultInstance in " + messageClassName, e);
} catch (SecurityException e) {
throw new RuntimeException("Unable to call defaultInstance in " + messageClassName, e);
} catch (IllegalAccessException e) {
throw new RuntimeException("Unable to call parsePartialFrom", e);
} catch (InvalidProtocolBufferException e) {
throw new RuntimeException("Unable to understand proto buffer", e);
}
}
private Class<?> resolveMessageClass() throws ClassNotFoundException { private Class<?> resolveMessageClass() throws ClassNotFoundException {
return messageClass != null ? messageClass : Class.forName(messageClassName); return messageClass != null ? messageClass : Class.forName(messageClassName);
} }

Loading…
Cancel
Save