Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ jobs:
- name: 'Test'
shell: bash
run: mvn test -B
- name: 'SanityCheck'
shell: bash
run: mvn rewrite:dryRun
- name: 'Javadoc'
shell: bash
run: mvn -P '!examples' javadoc:javadoc
Expand Down
15 changes: 15 additions & 0 deletions .idea/checkstyle-idea.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/palantir-java-format.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion annotation/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
<version>1.0-HEAD-SNAPSHOT</version>
</parent>

<name>@BugPattern annotation</name>
<artifactId>error_prone_annotation</artifactId>
<name>@BugPattern annotation</name>

<licenses>
<license>
Expand Down
18 changes: 10 additions & 8 deletions annotations/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,15 @@
<version>1.0-HEAD-SNAPSHOT</version>
</parent>

<name>error-prone annotations</name>
<artifactId>error_prone_annotations</artifactId>
<name>error-prone annotations</name>

<licenses>
<license>
<name>Apache 2.0</name>
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
</license>
</licenses>

<dependencies>
<dependency>
Expand All @@ -36,18 +43,12 @@
</dependency>
</dependencies>

<licenses>
<license>
<name>Apache 2.0</name>
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
</license>
</licenses>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.14.1</version>
<configuration>
<compilerArgs combine.self="override" />
</configuration>
Expand Down Expand Up @@ -79,6 +80,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.4.2</version>
<configuration>
<archive>
<manifestEntries>
Expand Down
17 changes: 15 additions & 2 deletions check_api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
<version>1.0-HEAD-SNAPSHOT</version>
</parent>

<name>error-prone check api</name>
<artifactId>error_prone_check_api</artifactId>
<name>error-prone check api</name>

<licenses>
<license>
Expand All @@ -49,6 +49,12 @@
<artifactId>jspecify</artifactId>
<version>${jspecify.version}</version>
</dependency>
<dependency>
<groupId>jakarta.annotation</groupId>
<artifactId>jakarta.annotation-api</artifactId>
<version>1.3.5</version>
<scope>provided</scope>
</dependency>
<dependency>
<!-- GPLv2 with Classpath Exception -->
<groupId>io.github.eisop</groupId>
Expand Down Expand Up @@ -103,6 +109,12 @@
<version>${truth.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>jakarta.inject</groupId>
<artifactId>jakarta.inject-api</artifactId>
<version>1.0.3</version>
<scope>test</scope>
</dependency>
<dependency>
<!-- MIT -->
<groupId>org.mockito</groupId>
Expand Down Expand Up @@ -149,6 +161,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.14.1</version>
<configuration>
<annotationProcessorPaths>
<path>
Expand Down Expand Up @@ -189,7 +202,7 @@
<version>24</version>
</jdkToolchain>
<compileSourceRoots>
<compileSourceRoot>${basedir}/src/main/java24</compileSourceRoot>
<compileSourceRoot>${project.basedir}/src/main/java24</compileSourceRoot>
</compileSourceRoots>
<!-- multiReleaseOutput requires setting release -->
<outputDirectory>${project.build.outputDirectory}/META-INF/versions/24</outputDirectory>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import com.sun.tools.javac.tree.EndPosTable;
import com.sun.tools.javac.tree.JCTree.JCCompilationUnit;
import java.net.URI;
import java.nio.file.Paths;
import java.nio.file.Path;
import java.util.LinkedHashSet;
import java.util.Objects;
import java.util.Set;
Expand Down Expand Up @@ -68,7 +68,7 @@ private DescriptionBasedDiff(
URI sourceFileUri = compilationUnit.getSourceFile().toUri();
this.sourcePath =
(sourceFileUri.isAbsolute() && Objects.equals(sourceFileUri.getScheme(), "file"))
? Paths.get(sourceFileUri).toAbsolutePath().toString()
? Path.of(sourceFileUri).toAbsolutePath().toString()
: sourceFileUri.getPath();
this.ignoreOverlappingFixes = ignoreOverlappingFixes;
this.importsToAdd = new LinkedHashSet<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,20 +87,18 @@ private Optional<Nullness> getNullness(InferenceVariable iv) {
result =
constraintGraph.predecessors(iv).stream()
.map(this::getNullness)
.filter(Optional::isPresent)
.map(Optional::get)
.flatMap(Optional::stream)
.reduce(Nullness::leastUpperBound); // use least upper bound (lub) to combine
// 2. If not, resolve successors and use them as upper bounds
if (!result.isPresent()) {
if (result.isEmpty()) {
result =
constraintGraph.successors(iv).stream()
.map(this::getNullness)
.filter(Optional::isPresent)
.map(Optional::get)
.flatMap(Optional::stream)
.reduce(Nullness::greatestLowerBound); // use greatest lower bound (glb) to combine
}

checkState(!inferredMemoTable.put(iv, result).isPresent());
checkState(inferredMemoTable.put(iv, result).isEmpty());
return result;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,14 +153,14 @@ private void generateConstraintsFromAnnotations(

Optional<Nullness> fromAnnotations =
extractExplicitNullness(declaredType, argSelector.isEmpty() ? decl : null);
if (!fromAnnotations.isPresent()) {
if (fromAnnotations.isEmpty()) {
// Check declared type before inferred type so that type annotations on the declaration take
// precedence (just like declaration annotations) over annotations on the inferred type.
// For instance, we want a @Nullable T m() to take precedence over annotations on T's inferred
// type (e.g., @NotNull String), whether @Nullable is a declaration or type annotation.
fromAnnotations = NullnessAnnotations.fromAnnotationsOn(inferredType);
}
if (!fromAnnotations.isPresent()) {
if (fromAnnotations.isEmpty()) {
if (declaredType instanceof TypeVariable typeVariable) {
// Check bounds second so explicit annotations take precedence. Even for bounds we still use
// equality constraint below since we have to assume the bound as the "worst" case.
Expand Down Expand Up @@ -482,7 +482,7 @@ private void generateConstraintsForWrite(
boolean isBound = false;
Optional<Nullness> fromAnnotations =
extractExplicitNullness(lType, argSelector.isEmpty() ? decl : null);
if (!fromAnnotations.isPresent()) {
if (fromAnnotations.isEmpty()) {
if (lType instanceof TypeVariable typeVariable) {
fromAnnotations = NullnessAnnotations.getUpperBound(typeVariable);
isBound = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1132,7 +1132,7 @@ public static SuggestedFix.Builder addValuesToAnnotationArgument(
.replaceFirst("\\(\\)", "(" + parameterPrefix + newArgument(newValues) + ")"));
}
Optional<ExpressionTree> maybeExistingArgument = findArgument(annotation, parameterName);
if (!maybeExistingArgument.isPresent()) {
if (maybeExistingArgument.isEmpty()) {
return SuggestedFix.builder()
.prefixWith(
annotation.getArguments().getFirst(),
Expand Down Expand Up @@ -1192,7 +1192,7 @@ public static SuggestedFix.Builder updateAnnotationArgumentValues(
+ ')');
}
Optional<ExpressionTree> maybeExistingArgument = findArgument(annotation, parameterName);
if (!maybeExistingArgument.isPresent()) {
if (maybeExistingArgument.isEmpty()) {
return SuggestedFix.builder()
.prefixWith(
annotation.getArguments().getFirst(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,7 @@ public static Matcher<ExpressionTree> compile(Iterable<Rule> rules) {
// First collect all the nodes that accept any token at all
for (Node node : curr) {
for (Map.Entry<Optional<Token>, Node> entry : nfa.row(node).entrySet()) {
if (!entry.getKey().isPresent()) {
if (entry.getKey().isEmpty()) {
acceptsAny.add(entry.getValue());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ private static ImmutableList<Commented<ExpressionTree>> findCommentsForArguments

CharSequence sourceCode = state.getSourceCode();
Optional<Integer> endPosition = computeEndPosition(tree, sourceCode, state);
if (!endPosition.isPresent()) {
if (endPosition.isEmpty()) {
return noComments(arguments);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public static class ComputeEndPosition extends BugChecker implements MethodInvoc
public Description matchMethodInvocation(MethodInvocationTree tree, VisitorState state) {
CharSequence sourceCode = state.getSourceCode();
Optional<Integer> endPosition = Comments.computeEndPosition(tree, sourceCode, state);
if (!endPosition.isPresent()) {
if (endPosition.isEmpty()) {
return Description.NO_MATCH;
}
int startPosition = endPosition.get();
Expand Down
19 changes: 16 additions & 3 deletions core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
<version>1.0-HEAD-SNAPSHOT</version>
</parent>

<name>error-prone library</name>
<artifactId>error_prone_core</artifactId>
<name>error-prone library</name>

<licenses>
<license>
Expand Down Expand Up @@ -74,6 +74,12 @@
<artifactId>pcollections</artifactId>
<version>4.0.1</version>
</dependency>
<dependency>
<groupId>jakarta.annotation</groupId>
<artifactId>jakarta.annotation-api</artifactId>
<version>1.3.5</version>
<scope>provided</scope>
</dependency>
<dependency>
<!-- Apache 2.0 -->
<groupId>com.google.guava</groupId>
Expand All @@ -99,6 +105,11 @@
<artifactId>dataflow-errorprone</artifactId>
<version>${dataflow.version}</version>
</dependency>
<dependency>
<groupId>jakarta.inject</groupId>
<artifactId>jakarta.inject-api</artifactId>
<version>1.0.3</version>
</dependency>
<dependency>
<!-- Apache 2.0 -->
<groupId>com.google.auto.value</groupId>
Expand Down Expand Up @@ -190,7 +201,7 @@
<version>5.1.0</version>
<scope>test</scope>
</dependency>
<!-- Apache 2.0 -->
<!-- Apache 2.0 -->
<dependency>
<groupId>com.google.inject.extensions</groupId>
<artifactId>guice-testlib</artifactId>
Expand Down Expand Up @@ -354,7 +365,7 @@
<artifactId>jspecify</artifactId>
<version>${jspecify.version}</version>
</dependency>
<!-- Apache 2.0 -->
<!-- Apache 2.0 -->
<dependency>
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
Expand All @@ -374,6 +385,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.14.1</version>
<configuration>
<annotationProcessorPaths>
<path>
Expand Down Expand Up @@ -485,6 +497,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.14.1</version>
<configuration>
<annotationProcessorPaths>
<path>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ public Description matchNewClass(NewClassTree newClassTree, VisitorState state)
public Description matchMemberReference(MemberReferenceTree tree, VisitorState state) {
Description description =
matcher.get().matches(tree, state) ? describeReturnValueIgnored(tree, state) : NO_MATCH;
if (!lostType(state).isPresent() || !description.equals(NO_MATCH)) {
if (lostType(state).isEmpty() || !description.equals(NO_MATCH)) {
return description;
}
if (lostReferenceTreeMatcher.get().matches(tree, state)) {
Expand Down Expand Up @@ -335,7 +335,7 @@ && matchingMethods(
* this a constructor call or build() call?"
*/
if (parent instanceof ExpressionStatementTree
&& !constantExpressions.constantExpression(invocationTree, state).isPresent()
&& constantExpressions.constantExpression(invocationTree, state).isEmpty()
&& considerBlanketFixes) {
ImmutableSet<String> identifiersInScope =
findAllIdents(state).stream().map(v -> v.name.toString()).collect(toImmutableSet());
Expand Down Expand Up @@ -407,7 +407,7 @@ protected String getMessage(Name name) {

private Description checkLostType(MethodInvocationTree tree, VisitorState state) {
Optional<Type> optionalType = lostType(state);
if (!optionalType.isPresent()) {
if (optionalType.isEmpty()) {
return NO_MATCH;
}

Expand Down Expand Up @@ -567,7 +567,7 @@ private static boolean isExemptedInterfaceMethod(MethodSymbol symbol, VisitorSta
@Override
public Description matchReturn(ReturnTree tree, VisitorState state) {
Optional<Type> optionalType = lostType(state);
if (!optionalType.isPresent()) {
if (optionalType.isEmpty()) {
return NO_MATCH;
}
Type objectType = state.getSymtab().objectType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public Description matchMethodInvocation(MethodInvocationTree tree, VisitorState
}
Optional<JCCatch> maybeCatchTree =
catchesType(tryStatement, state.getSymtab().assertionErrorType, state);
if (!maybeCatchTree.isPresent()) {
if (maybeCatchTree.isEmpty()) {
return NO_MATCH;
}
JCCatch catchTree = maybeCatchTree.get();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ public Description matchNewClass(NewClassTree tree, VisitorState state) {
Arrays.stream(CollectionTypes.values())
.filter(type -> type.constructorMatcher.matches(tree, state))
.findFirst();
if (!collectionType.isPresent()) {
if (collectionType.isEmpty()) {
return NO_MATCH;
}
Description.Builder description = buildDescription(tree);
Expand Down
Loading
Loading