Skip to content

Commit 09cab82

Browse files
author
Hao Nguyen
committed
Down integrate to GitHub
1 parent 6153f80 commit 09cab82

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+1794
-2012
lines changed

java/core/src/main/java/com/google/protobuf/AbstractMessage.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ public FieldDescriptor getOneofFieldDescriptor(OneofDescriptor oneof) {
108108

109109
@Override
110110
public final String toString() {
111-
return TextFormat.printToString(this);
111+
return TextFormat.printer().printToString(this);
112112
}
113113

114114
@Override
@@ -468,7 +468,7 @@ public Message.Builder getRepeatedFieldBuilder(final FieldDescriptor field, int
468468

469469
@Override
470470
public String toString() {
471-
return TextFormat.printToString(this);
471+
return TextFormat.printer().printToString(this);
472472
}
473473

474474
/** Construct an UninitializedMessageException reporting missing fields in the given message. */

java/core/src/main/java/com/google/protobuf/ExtensionRegistryLite.java

+13-3
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,10 @@ public class ExtensionRegistryLite {
7676
// applications. Need to support this feature on smaller granularity.
7777
private static volatile boolean eagerlyParseMessageSets = false;
7878

79+
// short circuit the ExtensionRegistryFactory via assumevalues trickery
80+
@SuppressWarnings("JavaOptionalSuggestions")
81+
private static boolean doFullRuntimeInheritanceCheck = true;
82+
7983
// Visible for testing.
8084
static final String EXTENSION_CLASS_NAME = "com.google.protobuf.Extension";
8185

@@ -107,7 +111,9 @@ public static void setEagerlyParseMessageSets(boolean isEagerlyParse) {
107111
* available.
108112
*/
109113
public static ExtensionRegistryLite newInstance() {
110-
return ExtensionRegistryFactory.create();
114+
return doFullRuntimeInheritanceCheck
115+
? ExtensionRegistryFactory.create()
116+
: new ExtensionRegistryLite();
111117
}
112118

113119
private static volatile ExtensionRegistryLite emptyRegistry;
@@ -122,7 +128,11 @@ public static ExtensionRegistryLite getEmptyRegistry() {
122128
synchronized (ExtensionRegistryLite.class) {
123129
result = emptyRegistry;
124130
if (result == null) {
125-
result = emptyRegistry = ExtensionRegistryFactory.createEmpty();
131+
result =
132+
emptyRegistry =
133+
doFullRuntimeInheritanceCheck
134+
? ExtensionRegistryFactory.createEmpty()
135+
: EMPTY_REGISTRY_LITE;
126136
}
127137
}
128138
}
@@ -163,7 +173,7 @@ public final void add(ExtensionLite<?, ?> extension) {
163173
if (GeneratedMessageLite.GeneratedExtension.class.isAssignableFrom(extension.getClass())) {
164174
add((GeneratedMessageLite.GeneratedExtension<?, ?>) extension);
165175
}
166-
if (ExtensionRegistryFactory.isFullRegistry(this)) {
176+
if (doFullRuntimeInheritanceCheck && ExtensionRegistryFactory.isFullRegistry(this)) {
167177
try {
168178
this.getClass().getMethod("add", extensionClass).invoke(this, extension);
169179
} catch (Exception e) {

java/core/src/main/java/com/google/protobuf/Message.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public interface Message extends MessageLite, MessageOrBuilder {
8585

8686
/**
8787
* Converts the message to a string in protocol buffer text format. This is just a trivial wrapper
88-
* around {@link TextFormat#printToString(MessageOrBuilder)}.
88+
* around {@link TextFormat.Printer#printToString(MessageOrBuilder)}.
8989
*/
9090
@Override
9191
String toString();

0 commit comments

Comments
 (0)