Skip to content

Commit 7733b92

Browse files
committed
Extend ProtoStringFieldReferenceEquality to support older versions of protobuf
1 parent 691c64a commit 7733b92

File tree

2 files changed

+8
-10
lines changed

2 files changed

+8
-10
lines changed

core/src/main/java/com/google/errorprone/bugpatterns/ProtoStringFieldReferenceEquality.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,11 @@
3838
summary = "Comparing protobuf fields of type String using reference equality")
3939
public class ProtoStringFieldReferenceEquality extends BugChecker implements BinaryTreeMatcher {
4040

41-
private static final String PROTO_SUPER_CLASS = "com.google.protobuf.GeneratedMessage";
42-
43-
private static final String LITE_PROTO_SUPER_CLASS = "com.google.protobuf.GeneratedMessageLite";
41+
private static final String LITE_PROTO_INTERFACE = "com.google.protobuf.MessageLite";
4442

4543
private static final Matcher<ExpressionTree> PROTO_STRING_METHOD =
4644
allOf(
47-
instanceMethod().onDescendantOfAny(PROTO_SUPER_CLASS, LITE_PROTO_SUPER_CLASS),
45+
instanceMethod().onDescendantOf(LITE_PROTO_INTERFACE),
4846
isSameType(Suppliers.STRING_TYPE));
4947

5048
@Override

core/src/test/java/com/google/errorprone/bugpatterns/ProtoStringFieldReferenceEqualityTest.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,16 @@ public class ProtoStringFieldReferenceEqualityTest {
3232
public void positive() {
3333
compilationHelper
3434
.addSourceLines(
35-
"com/google/protobuf/GeneratedMessage.java",
35+
"com/google/protobuf/MessageLite.java",
3636
"""
3737
package com.google.protobuf;
3838
39-
public class GeneratedMessage {}
39+
public interface MessageLite {}
4040
""")
4141
.addSourceLines(
4242
"Proto.java",
4343
"""
44-
public abstract class Proto extends com.google.protobuf.GeneratedMessage {
44+
public abstract class Proto implements com.google.protobuf.MessageLite {
4545
public abstract String getMessage();
4646
}
4747
""")
@@ -68,16 +68,16 @@ boolean g(Proto proto) {
6868
public void negative() {
6969
compilationHelper
7070
.addSourceLines(
71-
"com/google/protobuf/GeneratedMessage.java",
71+
"com/google/protobuf/MessageLite.java",
7272
"""
7373
package com.google.protobuf;
7474
75-
public class GeneratedMessage {}
75+
public interface MessageLite {}
7676
""")
7777
.addSourceLines(
7878
"Proto.java",
7979
"""
80-
public abstract class Proto extends com.google.protobuf.GeneratedMessage {
80+
public abstract class Proto implements com.google.protobuf.MessageLite {
8181
public abstract int getId();
8282
8383
public abstract String getMessage();

0 commit comments

Comments
 (0)