Skip to content

Commit 8cc2dd3

Browse files

File tree

10 files changed

+54
-34
lines changed

10 files changed

+54
-34
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,8 @@ that your build is executed using JDK 21 or above, but supports builds that
9898
</arg>
9999
<arg>-XDcompilePolicy=simple</arg>
100100
<arg>--should-stop=ifError=FLOW</arg>
101+
<!-- Add this flag if you build with JDK 21. -->
102+
<!-- <arg>-XDaddTypeAnnotationsToSymbol=true</arg> -->
101103
</compilerArgs>
102104
<!-- Enable this if you'd like to fail your build upon warnings. -->
103105
<!-- <failOnWarning>true</failOnWarning> -->

error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/SuggestedFixRulesTestInput.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ SuggestedFix.Builder testSuggestedFixToBuilder() {
1212
}
1313

1414
SuggestedFix testSuggestedFixDelete() {
15-
return SuggestedFix.builder().delete(null).build();
15+
return SuggestedFix.builder().delete((Tree) null).build();
1616
}
1717

1818
SuggestedFix testSuggestedFixReplaceTree() {
19-
return SuggestedFix.builder().replace(null, "foo").build();
19+
return SuggestedFix.builder().replace((Tree) null, "foo").build();
2020
}
2121

2222
SuggestedFix testSuggestedFixReplaceStartEnd() {
@@ -34,10 +34,10 @@ SuggestedFix testSuggestedFixSwap() {
3434
}
3535

3636
SuggestedFix testSuggestedFixPrefixWith() {
37-
return SuggestedFix.builder().prefixWith(null, "foo").build();
37+
return SuggestedFix.builder().prefixWith((Tree) null, "foo").build();
3838
}
3939

4040
SuggestedFix testSuggestedFixPostfixWith() {
41-
return SuggestedFix.builder().postfixWith(null, "foo").build();
41+
return SuggestedFix.builder().postfixWith((Tree) null, "foo").build();
4242
}
4343
}

error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/SuggestedFixRulesTestOutput.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ SuggestedFix.Builder testSuggestedFixToBuilder() {
1212
}
1313

1414
SuggestedFix testSuggestedFixDelete() {
15-
return SuggestedFix.delete(null);
15+
return SuggestedFix.delete((Tree) null);
1616
}
1717

1818
SuggestedFix testSuggestedFixReplaceTree() {
19-
return SuggestedFix.replace(null, "foo");
19+
return SuggestedFix.replace((Tree) null, "foo");
2020
}
2121

2222
SuggestedFix testSuggestedFixReplaceStartEnd() {
@@ -32,10 +32,10 @@ SuggestedFix testSuggestedFixSwap() {
3232
}
3333

3434
SuggestedFix testSuggestedFixPrefixWith() {
35-
return SuggestedFix.prefixWith(null, "foo");
35+
return SuggestedFix.prefixWith((Tree) null, "foo");
3636
}
3737

3838
SuggestedFix testSuggestedFixPostfixWith() {
39-
return SuggestedFix.postfixWith(null, "foo");
39+
return SuggestedFix.postfixWith((Tree) null, "foo");
4040
}
4141
}

integration-tests/checkstyle-init.patch

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,12 @@
1313
<dependency>
1414
<groupId>nl.jqno.equalsverifier</groupId>
1515
<artifactId>equalsverifier</artifactId>
16-
@@ -2574,6 +2580,8 @@
16+
@@ -2571,9 +2577,13 @@
17+
<arg>-Xpkginfo:always</arg>
18+
<arg>-XDcompilePolicy=simple</arg>
19+
<arg>--should-stop=ifError=FLOW</arg>
20+
+ <!-- XXX: Drop this flag once the project uses Error Prone 2.46.0+ by default. -->
21+
+ <arg>-XDaddTypeAnnotationsToSymbol=true</arg>
1722
<arg>
1823
-Xplugin:ErrorProne ${error-prone.configuration-args}
1924
</arg>
@@ -22,7 +27,7 @@
2227
</compilerArgs>
2328
<annotationProcessorPaths>
2429
<path>
25-
@@ -2586,6 +2594,11 @@
30+
@@ -2586,6 +2596,11 @@
2631
<artifactId>error-prone-contrib</artifactId>
2732
<version>${error-prone-support.version}</version>
2833
</path>
@@ -34,12 +39,12 @@
3439
</annotationProcessorPaths>
3540
</configuration>
3641
</execution>
37-
@@ -2627,11 +2640,14 @@
42+
@@ -2627,11 +2642,14 @@
3843
<arg>--should-stop=ifError=FLOW</arg>
3944
<arg>-Xpkginfo:always</arg>
4045
<arg>-XDcompilePolicy=simple</arg>
41-
+ <!-- XXX: Drop this flag once the project uses Error Prone 2.36.0+ by default. -->
42-
+ <arg>--should-stop=ifError=FLOW</arg>
46+
+ <!-- XXX: Drop this flag once the project uses Error Prone 2.46.0+ by default. -->
47+
+ <arg>-XDaddTypeAnnotationsToSymbol=true</arg>
4348
<arg>
4449
-Xplugin:ErrorProne \
4550
- -XepExcludedPaths:.*[\\/]resources[\\/].* \
@@ -50,7 +55,7 @@
5055
</compilerArgs>
5156
<annotationProcessorPaths>
5257
<path>
53-
@@ -2644,6 +2660,11 @@
58+
@@ -2644,6 +2662,11 @@
5459
<artifactId>error-prone-contrib</artifactId>
5560
<version>${error-prone-support.version}</version>
5661
</path>

integration-tests/metrics-init.patch

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,16 +52,18 @@
5252
<profiles>
5353
<profile>
5454
<id>jdk17</id>
55-
@@ -145,7 +166,7 @@
55+
@@ -145,7 +166,9 @@
5656
<arg>-Xlint:all</arg>
5757
<arg>-XDcompilePolicy=simple</arg>
5858
<arg>--should-stop=ifError=FLOW</arg>
5959
- <arg>-Xplugin:ErrorProne -XepExcludedPaths:.*/target/generated-sources/.*</arg>
60+
+ <!-- XXX: Drop this flag once the project uses Error Prone 2.46.0+ by default. -->
61+
+ <arg>-XDaddTypeAnnotationsToSymbol=true</arg>
6062
+ <arg>-Xplugin:ErrorProne -XepExcludedPaths:.*/target/generated-sources/.* ${error-prone.configuration-args}</arg>
6163
<arg>-J--add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED</arg>
6264
<arg>-J--add-exports=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED</arg>
6365
<arg>-J--add-exports=jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED</arg>
64-
@@ -156,12 +177,24 @@
66+
@@ -156,12 +179,24 @@
6567
<arg>-J--add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED</arg>
6668
<arg>-J--add-opens=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED</arg>
6769
<arg>-J--add-opens=jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED</arg>
@@ -87,7 +89,7 @@
8789
</path>
8890
</annotationProcessorPaths>
8991
</configuration>
90-
@@ -283,7 +316,7 @@
92+
@@ -283,7 +318,7 @@
9193
<groupId>org.apache.maven.plugins</groupId>
9294
<artifactId>maven-compiler-plugin</artifactId>
9395
<configuration>

integration-tests/prometheus-java-client-init.patch

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
.withLogConsumer(LogConsumer.withPrefix(sampleApp))
1212
--- a/pom.xml
1313
+++ b/pom.xml
14-
@@ -252,9 +252,9 @@
14+
@@ -252,36 +252,49 @@
1515
<release>${java.version}</release>
1616
<source>${java.version}</source>
1717
<target>${java.version}</target>
@@ -24,7 +24,14 @@
2424
<showWarnings>true</showWarnings>
2525
<compilerArgs>
2626
<arg>-Xlint:all,-serial,-processing,-options</arg>
27-
@@ -267,21 +267,32 @@
27+
<arg>${warnings}</arg>
28+
<arg>--should-stop=ifError=FLOW</arg>
29+
<arg>-XDcompilePolicy=simple</arg>
30+
+ <!-- XXX: Drop this flag once the project uses Error Prone 2.46.0+ by default. -->
31+
+ <arg>-XDaddTypeAnnotationsToSymbol=true</arg>
32+
<arg>
33+
-Xplugin:ErrorProne
34+
-Xep:AlmostJavadoc:OFF
2835
-Xep:MissingSummary:OFF
2936
-Xep:LongDoubleConversion:OFF
3037
-Xep:StringSplitter:OFF
@@ -59,7 +66,7 @@
5966
<!-- Other annotation processors go here.
6067

6168
If 'annotationProcessorPaths' is set, processors will no longer be
62-
@@ -394,7 +405,6 @@
69+
@@ -394,7 +407,6 @@
6370
<groupId>com.google.guava</groupId>
6471
<artifactId>guava</artifactId>
6572
<version>${guava.version}</version>

pom.xml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@
205205
<version.auto-service>1.1.1</version.auto-service>
206206
<version.error-prone>${version.error-prone-orig}</version.error-prone>
207207
<version.error-prone-fork>${version.error-prone-orig}-picnic-1</version.error-prone-fork>
208-
<version.error-prone-orig>2.45.0</version.error-prone-orig>
208+
<version.error-prone-orig>2.46.0</version.error-prone-orig>
209209
<version.jdk>21</version.jdk>
210210
<version.maven>3.9.12</version.maven>
211211
<version.pitest-git>2.3.2</version.pitest-git>
@@ -1924,6 +1924,9 @@
19241924
always contains forward-slash path
19251925
separators. -->
19261926
-XepExcludedPaths:(?!.*/src/[^/]+/java/.*).*
1927+
<!-- We have package-level `@NullMarked`
1928+
annotations. -->
1929+
-Xep:AddNullMarkedToClass:OFF
19271930
<!-- XXX: Enable this once we open-source
19281931
this library. -->
19291932
-Xep:BetaApi:OFF

refaster-runner/src/main/java/tech/picnic/errorprone/refaster/runner/Refaster.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,10 @@
2929
import com.google.errorprone.annotations.CanIgnoreReturnValue;
3030
import com.google.errorprone.bugpatterns.BugChecker;
3131
import com.google.errorprone.bugpatterns.BugChecker.CompilationUnitTreeMatcher;
32+
import com.google.errorprone.fixes.ErrorProneEndPosTable;
3233
import com.google.errorprone.fixes.Replacement;
3334
import com.google.errorprone.matchers.Description;
3435
import com.sun.source.tree.CompilationUnitTree;
35-
import com.sun.tools.javac.tree.EndPosTable;
36-
import com.sun.tools.javac.tree.JCTree.JCCompilationUnit;
3736
import java.util.ArrayList;
3837
import java.util.Comparator;
3938
import java.util.List;
@@ -91,7 +90,7 @@ public Description matchCompilationUnit(CompilationUnitTree tree, VisitorState s
9190
codeTransformer.apply(state.getPath(), new SubContext(state.context), matches::add);
9291

9392
/* Then apply them. */
94-
applyMatches(matches, ((JCCompilationUnit) tree).endPositions, state);
93+
applyMatches(matches, ErrorProneEndPosTable.create(tree), state);
9594

9695
/* Any matches were already reported by the code above, directly to the `VisitorState`. */
9796
return Description.NO_MATCH;
@@ -108,7 +107,7 @@ public Description matchCompilationUnit(CompilationUnitTree tree, VisitorState s
108107
// XXX: This selection logic solves an issue described in
109108
// https://github.com/google/error-prone/issues/559. Consider contributing it back upstream.
110109
private void applyMatches(
111-
Iterable<Description> allMatches, EndPosTable endPositions, VisitorState state) {
110+
Iterable<Description> allMatches, ErrorProneEndPosTable endPositions, VisitorState state) {
112111
ImmutableList<Description> byReplacementSize =
113112
ImmutableList.sortedCopyOf(
114113
Comparator.<Description>comparingInt(d -> getReplacedCodeSize(d, endPositions))
@@ -170,25 +169,27 @@ private static Description augmentDescription(
170169
.build();
171170
}
172171

173-
private static int getReplacedCodeSize(Description description, EndPosTable endPositions) {
172+
private static int getReplacedCodeSize(
173+
Description description, ErrorProneEndPosTable endPositions) {
174174
return getReplacements(description, endPositions).mapToInt(Replacement::length).sum();
175175
}
176176

177177
// XXX: It might be nicer to prefer the shortest replacement _post formatting_.
178-
private static int getInsertedCodeSize(Description description, EndPosTable endPositions) {
178+
private static int getInsertedCodeSize(
179+
Description description, ErrorProneEndPosTable endPositions) {
179180
return getReplacements(description, endPositions).mapToInt(r -> r.replaceWith().length()).sum();
180181
}
181182

182183
private static ImmutableRangeSet<Integer> getReplacementRanges(
183-
Description description, EndPosTable endPositions) {
184+
Description description, ErrorProneEndPosTable endPositions) {
184185
return getReplacements(description, endPositions)
185186
.map(Replacement::range)
186187
.filter(not(Range::isEmpty))
187188
.collect(toImmutableRangeSet());
188189
}
189190

190191
private static Stream<Replacement> getReplacements(
191-
Description description, EndPosTable endPositions) {
192+
Description description, ErrorProneEndPosTable endPositions) {
192193
return description.fixes.stream().flatMap(fix -> fix.getReplacements(endPositions).stream());
193194
}
194195

refaster-support/src/test/java/tech/picnic/errorprone/refaster/AnnotatedCompositeCodeTransformerTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@
1919
import com.google.errorprone.CodeTransformer;
2020
import com.google.errorprone.DescriptionListener;
2121
import com.google.errorprone.ErrorProneOptions;
22+
import com.google.errorprone.fixes.ErrorPronePosition;
2223
import com.google.errorprone.fixes.Fix;
2324
import com.google.errorprone.matchers.Description;
2425
import com.sun.source.util.TreePath;
2526
import com.sun.tools.javac.util.Context;
26-
import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition;
2727
import java.lang.annotation.Annotation;
2828
import java.util.ArrayList;
2929
import java.util.List;
@@ -39,7 +39,7 @@
3939
// through `RefasterTest`, but ideally it is covered by tests in this class, closer to the code that
4040
// implements the relevant logic.) See the comment in `#context()` below.
4141
final class AnnotatedCompositeCodeTransformerTest {
42-
private static final DiagnosticPosition DUMMY_POSITION = mock();
42+
private static final ErrorPronePosition DUMMY_POSITION = mock();
4343
private static final Fix DUMMY_FIX = mock();
4444
private static final TreePath DUMMY_PATH = mock();
4545
private static final String DEFAULT_PACKAGE = "";

refaster-test-support/src/main/java/tech/picnic/errorprone/refaster/test/RefasterRuleCollection.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import com.google.errorprone.VisitorState;
2828
import com.google.errorprone.bugpatterns.BugChecker;
2929
import com.google.errorprone.bugpatterns.BugChecker.CompilationUnitTreeMatcher;
30+
import com.google.errorprone.fixes.ErrorProneEndPosTable;
3031
import com.google.errorprone.fixes.Replacement;
3132
import com.google.errorprone.fixes.SuggestedFix;
3233
import com.google.errorprone.matchers.Description;
@@ -37,7 +38,6 @@
3738
import com.sun.source.tree.MethodTree;
3839
import com.sun.source.tree.Tree;
3940
import com.sun.source.util.TreeScanner;
40-
import com.sun.tools.javac.tree.EndPosTable;
4141
import com.sun.tools.javac.tree.JCTree.JCCompilationUnit;
4242
import com.sun.tools.javac.util.Position;
4343
import java.io.IOException;
@@ -152,7 +152,7 @@ public Description matchCompilationUnit(CompilationUnitTree tree, VisitorState s
152152
.withPath(state.getPath()));
153153

154154
ImmutableRangeMap<Integer, String> indexedMatches =
155-
indexRuleMatches(matches, ((JCCompilationUnit) tree).endPositions);
155+
indexRuleMatches(matches, ErrorProneEndPosTable.create(tree));
156156

157157
matches.forEach(state::reportMatch);
158158
reportMissingMatches(tree, indexedMatches, state);
@@ -185,7 +185,7 @@ private void reportIncorrectClassName(CompilationUnitTree tree, VisitorState sta
185185
}
186186

187187
private static ImmutableRangeMap<Integer, String> indexRuleMatches(
188-
List<Description> matches, EndPosTable endPositions) {
188+
List<Description> matches, ErrorProneEndPosTable endPositions) {
189189
ImmutableRangeMap.Builder<Integer, String> ruleMatches = ImmutableRangeMap.builder();
190190

191191
for (Description description : matches) {

0 commit comments

Comments
 (0)