Skip to content

Commit

Permalink
Fix JRuby conformance issue by loosening Java's JSONFormatter imple…
Browse files Browse the repository at this point in the history
…mentation to be more accepting of `DynamicMessage` instances of well-known types that have a descriptor with a different object identity but the same full name.

PiperOrigin-RevId: 712973356
  • Loading branch information
protobuf-github-bot authored and copybara-github committed Jan 11, 2025
1 parent 975bb07 commit e870a09
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
1 change: 0 additions & 1 deletion conformance/failure_list_jruby.txt
Original file line number Diff line number Diff line change
Expand Up @@ -144,4 +144,3 @@ Required.Editions_Proto2.ProtobufInput.UnknownOrdering.ProtobufOutput
Required.Editions_Proto3.ProtobufInput.UnknownOrdering.ProtobufOutput
Required.Proto2.ProtobufInput.UnknownOrdering.ProtobufOutput
Required.Proto3.ProtobufInput.UnknownOrdering.ProtobufOutput
Required.*.JsonInput.AnyWithNoType.JsonOutput # Failed to parse input or produce output.
11 changes: 11 additions & 0 deletions java/core/src/main/java/com/google/protobuf/AbstractMessage.java
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,17 @@ public int getSerializedSize() {
return memoizedSize;
}

/*
* This method will only ever return true if `this` and `other` have the same descriptor instance
* for their type (including a gencode message compared to a `DynamicMessage` constructed using
* the same descriptor instance).
*
* For reasons of backward compatibility, a comparison
* involving `DynamicMessage` that is constructed using semantically the same descriptor which
* was loaded separately (such that the reference identity of the descriptors does not match) will
* always return false even if there is otherwise no skew between the descriptors and the contents
* of the instances.
*/
@Override
public boolean equals(final Object other) {
if (other == this) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -862,7 +862,7 @@ public void print(PrinterImpl printer, MessageOrBuilder message) throws IOExcept

/** Prints google.protobuf.Any */
private void printAny(MessageOrBuilder message) throws IOException {
if (Any.getDefaultInstance().equals(message)) {
if (message.getDefaultInstanceForType().equals(message)) {
generator.print("{}");
return;
}
Expand Down

0 comments on commit e870a09

Please sign in to comment.