From e555bd23d077216ea40006c45eeaaa5aa385d921 Mon Sep 17 00:00:00 2001 From: Sandy Zhang Date: Fri, 1 Dec 2023 13:18:30 -0800 Subject: [PATCH] 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 --- .../com/google/protobuf/AbstractMessage.java | 40 ------------------- .../google/protobuf/GeneratedMessageLite.java | 29 +------------- 2 files changed, 1 insertion(+), 68 deletions(-) diff --git a/java/core/src/main/java/com/google/protobuf/AbstractMessage.java b/java/core/src/main/java/com/google/protobuf/AbstractMessage.java index f383625b25..30eccc1eca 100644 --- a/java/core/src/main/java/com/google/protobuf/AbstractMessage.java +++ b/java/core/src/main/java/com/google/protobuf/AbstractMessage.java @@ -538,44 +538,4 @@ public abstract class AbstractMessage 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 list) { - int hash = 1; - for (EnumLite e : list) { - hash = 31 * hash + hashEnum(e); - } - return hash; - } } diff --git a/java/core/src/main/java/com/google/protobuf/GeneratedMessageLite.java b/java/core/src/main/java/com/google/protobuf/GeneratedMessageLite.java index c153960de9..115f4288cd 100644 --- a/java/core/src/main/java/com/google/protobuf/GeneratedMessageLite.java +++ b/java/core/src/main/java/com/google/protobuf/GeneratedMessageLite.java @@ -1440,7 +1440,7 @@ public abstract class GeneratedMessageLite< } 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) { @@ -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 { return messageClass != null ? messageClass : Class.forName(messageClassName); }