Skip to content

Commit

Permalink
Breaking change: Remove deprecated runtime methods for compatibility …
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
zhangskz authored and Copybara-Service committed Dec 1, 2023
1 parent dfb8a4c commit e555bd2
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 68 deletions.
40 changes: 0 additions & 40 deletions java/core/src/main/java/com/google/protobuf/AbstractMessage.java
Original file line number Diff line number Diff line change
Expand Up @@ -538,44 +538,4 @@ public BuilderType mergeFrom(
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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1440,7 +1440,7 @@ protected Object readResolve() throws ObjectStreamException {
} catch (ClassNotFoundException e) {
throw new RuntimeException("Unable to find proto buffer class: " + messageClassName, e);
} catch (NoSuchFieldException e) {
return readResolveFallback();
throw new RuntimeException("Unable to find DEFAULT_INSTANCE in " + messageClassName, e);
} catch (SecurityException e) {
throw new RuntimeException("Unable to call DEFAULT_INSTANCE in " + messageClassName, e);
} catch (IllegalAccessException e) {
Expand All @@ -1450,33 +1450,6 @@ protected Object readResolve() throws ObjectStreamException {
}
}

/**
* @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 {
return messageClass != null ? messageClass : Class.forName(messageClassName);
}
Expand Down

0 comments on commit e555bd2

Please sign in to comment.