Skip to content

Commit

Permalink
Breaking Change: Remove obsolete runtime internalBuildGeneratedFileFr…
Browse files Browse the repository at this point in the history
…om which was for backwards compatibility with old gencode.

Remove `sentinel.proto` and references to it.

This was announced in https://protobuf.dev/news/2023-12-05/ per our Cross-Version Runtime Guarantees: https://protobuf.dev/support/cross-version-runtime-guarantee/

PiperOrigin-RevId: 597849821
  • Loading branch information
protobuf-github-bot authored and Copybara-Service committed Jan 12, 2024
1 parent e542443 commit 9310d2e
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 803 deletions.
61 changes: 1 addition & 60 deletions java/core/src/main/java/com/google/protobuf/Descriptors.java
Original file line number Diff line number Diff line change
Expand Up @@ -360,50 +360,6 @@ private static FileDescriptor[] findDescriptors(
return descriptors.toArray(new FileDescriptor[0]);
}

/**
* This method is for backward compatibility with generated code which passed an
* InternalDescriptorAssigner.
*/
@Deprecated
public static void internalBuildGeneratedFileFrom(
final String[] descriptorDataParts,
final FileDescriptor[] dependencies,
final InternalDescriptorAssigner descriptorAssigner) {
final byte[] descriptorBytes = latin1Cat(descriptorDataParts);

FileDescriptorProto proto;
try {
proto = FileDescriptorProto.parseFrom(descriptorBytes);
} catch (InvalidProtocolBufferException e) {
throw new IllegalArgumentException(
"Failed to parse protocol buffer descriptor for generated code.", e);
}

final FileDescriptor result;
try {
// When building descriptors for generated code, we allow unknown
// dependencies by default.
result = buildFrom(proto, dependencies, true);
} catch (DescriptorValidationException e) {
throw new IllegalArgumentException(
"Invalid embedded descriptor for \"" + proto.getName() + "\".", e);
}

final ExtensionRegistry registry = descriptorAssigner.assignDescriptors(result);

if (registry != null) {
// We must re-parse the proto using the registry.
try {
proto = FileDescriptorProto.parseFrom(descriptorBytes, registry);
} catch (InvalidProtocolBufferException e) {
throw new IllegalArgumentException(
"Failed to parse protocol buffer descriptor for generated code.", e);
}

result.setProto(proto);
}
}

/**
* This method is to be called by generated code only. It is equivalent to {@code buildFrom}
* except that the {@code FileDescriptorProto} is encoded in protocol buffer wire format.
Expand All @@ -430,22 +386,6 @@ public static FileDescriptor internalBuildGeneratedFileFrom(
}
}

/**
* This method is for backward compatibility with generated code which passed an
* InternalDescriptorAssigner.
*/
@Deprecated
public static void internalBuildGeneratedFileFrom(
final String[] descriptorDataParts,
final Class<?> descriptorOuterClass,
final String[] dependencyClassNames,
final String[] dependencyFileNames,
final InternalDescriptorAssigner descriptorAssigner) {
FileDescriptor[] dependencies =
findDescriptors(descriptorOuterClass, dependencyClassNames, dependencyFileNames);
internalBuildGeneratedFileFrom(descriptorDataParts, dependencies, descriptorAssigner);
}

/**
* This method is to be called by generated code only. It uses Java reflection to load the
* dependencies' descriptors.
Expand Down Expand Up @@ -2011,6 +1951,7 @@ private void setProto(final EnumDescriptorProto proto) {
* number. In generated Java code, all values with the same number after the first become aliases
* of the first. However, they still have independent EnumValueDescriptors.
*/
@SuppressWarnings("ShouldNotSubclass")
public static final class EnumValueDescriptor extends GenericDescriptor
implements Internal.EnumLite {
static final Comparator<EnumValueDescriptor> BY_NUMBER =
Expand Down
14 changes: 1 addition & 13 deletions ruby/src/main/java/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
load("@rules_java//java:defs.bzl", "java_library", "java_lite_proto_library", "java_proto_library")
load("@rules_java//java:defs.bzl", "java_library")
load("@rules_pkg//:mappings.bzl", "pkg_files", "strip_prefix")
load("@rules_proto//proto:defs.bzl", "proto_library")

java_library(
name = "protobuf_java",
Expand All @@ -21,21 +20,10 @@ java_library(
],
)

proto_library(
name = "sentinel_proto",
srcs = ["sentinel.proto"],
)

java_proto_library(
name = "sentinel_java_proto",
deps = [":sentinel_proto"],
)

pkg_files(
name = "dist_files",
srcs = glob([
"**/*.java",
"**/*.proto",
]),
strip_prefix = strip_prefix.from_root(""),
visibility = ["//ruby:__pkg__"],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -400,35 +400,30 @@ protected int size() {
}

private IRubyObject defaultValue(ThreadContext context) {
SentinelOuterClass.Sentinel sentinel = SentinelOuterClass.Sentinel.getDefaultInstance();
Object value;
switch (fieldType) {
case INT32:
value = sentinel.getDefaultInt32();
break;
case INT64:
value = sentinel.getDefaultInt64();
break;
case UINT32:
value = sentinel.getDefaultUnit32();
value = 0;
break;
case INT64:
case UINT64:
value = sentinel.getDefaultUint64();
value = 0L;
break;
case FLOAT:
value = sentinel.getDefaultFloat();
value = 0F;
break;
case DOUBLE:
value = sentinel.getDefaultDouble();
value = 0D;
break;
case BOOL:
value = sentinel.getDefaultBool();
value = false;
break;
case BYTES:
value = sentinel.getDefaultBytes();
value = com.google.protobuf.ByteString.EMPTY;
break;
case STRING:
value = sentinel.getDefaultString();
value = "";
break;
case ENUM:
IRubyObject defaultEnumLoc = context.runtime.newFixnum(0);
Expand Down
Loading

0 comments on commit 9310d2e

Please sign in to comment.