diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index fa44870f2..72947e9a3 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -8,9 +8,9 @@ jobs: build-without-cache: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - name: Set up JDK 11 - uses: actions/setup-java@v2 + uses: actions/setup-java@v4 with: java-version: 11 distribution: 'temurin' @@ -19,9 +19,9 @@ jobs: build-with-setup-java-cache: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - name: Set up JDK 11 - uses: actions/setup-java@v2 + uses: actions/setup-java@v4 with: java-version: 11 distribution: 'temurin' @@ -31,9 +31,9 @@ jobs: build-with-gradle-build-action-cache: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - name: Set up JDK 11 - uses: actions/setup-java@v2 + uses: actions/setup-java@v4 with: java-version: 11 distribution: 'temurin' @@ -43,9 +43,9 @@ jobs: build-with-upload-artifact: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - name: Set up JDK 11 - uses: actions/setup-java@v2 + uses: actions/setup-java@v4 with: java-version: 11 distribution: 'temurin' @@ -53,16 +53,16 @@ jobs: - name: Build with Gradle run: ./gradlew build --scan --no-daemon - name: Archive test report - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v4 with: name: Test report path: build/reports/tests/test parallel-processing-enabled-caching-disabled: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - name: Set up JDK 11 - uses: actions/setup-java@v2 + uses: actions/setup-java@v4 with: java-version: 11 distribution: 'temurin' @@ -73,9 +73,9 @@ jobs: parallel-processing-disabled-caching-disabled: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - name: Set up JDK 11 - uses: actions/setup-java@v2 + uses: actions/setup-java@v4 with: java-version: 11 distribution: 'temurin' @@ -87,9 +87,9 @@ jobs: parser-coinfiguration-17: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - name: Set up JDK 17 - uses: actions/setup-java@v2 + uses: actions/setup-java@v4 with: java-version: 17 distribution: 'temurin' diff --git a/annotator-core/src/main/java/edu/ucr/cs/riple/core/cache/downstream/DownstreamImpactCacheImpl.java b/annotator-core/src/main/java/edu/ucr/cs/riple/core/cache/downstream/DownstreamImpactCacheImpl.java index 4613abe18..7d09f1763 100644 --- a/annotator-core/src/main/java/edu/ucr/cs/riple/core/cache/downstream/DownstreamImpactCacheImpl.java +++ b/annotator-core/src/main/java/edu/ucr/cs/riple/core/cache/downstream/DownstreamImpactCacheImpl.java @@ -123,9 +123,7 @@ public void analyzeDownstreamDependencies() { .map( location -> new Fix( - new AddMarkerAnnotation(location, context.config.nullableAnnot), - "null", - false)) + new AddMarkerAnnotation(location, context.config.nullableAnnot), "null")) .collect(ImmutableSet.toImmutableSet()); DownstreamImpactEvaluator evaluator = new DownstreamImpactEvaluator(supplier); ImmutableSet reports = evaluator.evaluate(fixes); diff --git a/annotator-core/src/main/java/edu/ucr/cs/riple/core/checkers/nullaway/NullAway.java b/annotator-core/src/main/java/edu/ucr/cs/riple/core/checkers/nullaway/NullAway.java index 0c26c1a42..2f59d0e9b 100644 --- a/annotator-core/src/main/java/edu/ucr/cs/riple/core/checkers/nullaway/NullAway.java +++ b/annotator-core/src/main/java/edu/ucr/cs/riple/core/checkers/nullaway/NullAway.java @@ -139,7 +139,6 @@ private NullAwayError deserializeErrorFromTSVLine(ModuleInfo moduleInfo, String nonnullTarget == null ? Set.of() : Set.of(new AddMarkerAnnotation(nonnullTarget, config.nullableAnnot)); - return createError( errorType, errorMessage, diff --git a/annotator-core/src/main/java/edu/ucr/cs/riple/core/checkers/nullaway/NullAwayError.java b/annotator-core/src/main/java/edu/ucr/cs/riple/core/checkers/nullaway/NullAwayError.java index b343011a9..b6a3564c5 100644 --- a/annotator-core/src/main/java/edu/ucr/cs/riple/core/checkers/nullaway/NullAwayError.java +++ b/annotator-core/src/main/java/edu/ucr/cs/riple/core/checkers/nullaway/NullAwayError.java @@ -52,7 +52,7 @@ public NullAwayError( @Override protected Set computeFixesFromAnnotations(Set annotations) { return annotations.stream() - .map(annot -> new Fix(annot, messageType, true)) + .map(annot -> new Fix(annot, messageType)) .collect(Collectors.toSet()); } diff --git a/annotator-core/src/main/java/edu/ucr/cs/riple/core/evaluators/graph/Node.java b/annotator-core/src/main/java/edu/ucr/cs/riple/core/evaluators/graph/Node.java index dd45df133..fb577df0f 100644 --- a/annotator-core/src/main/java/edu/ucr/cs/riple/core/evaluators/graph/Node.java +++ b/annotator-core/src/main/java/edu/ucr/cs/riple/core/evaluators/graph/Node.java @@ -192,7 +192,6 @@ public void updateStatus( public void mergeTriggered() { this.tree.addAll(Error.getResolvingFixesOfErrors(this.triggeredErrors)); this.tree.addAll(triggeredFixesFromDownstreamErrors); - this.tree.forEach(fix -> fix.fixSourceIsInTarget = true); } @Override diff --git a/annotator-core/src/main/java/edu/ucr/cs/riple/core/evaluators/graph/processors/AbstractConflictGraphProcessor.java b/annotator-core/src/main/java/edu/ucr/cs/riple/core/evaluators/graph/processors/AbstractConflictGraphProcessor.java index 646113330..4dc80c06a 100644 --- a/annotator-core/src/main/java/edu/ucr/cs/riple/core/evaluators/graph/processors/AbstractConflictGraphProcessor.java +++ b/annotator-core/src/main/java/edu/ucr/cs/riple/core/evaluators/graph/processors/AbstractConflictGraphProcessor.java @@ -85,8 +85,7 @@ protected Set getTriggeredFixesFromDownstreamErrors(Node node) { new Fix( new AddMarkerAnnotation( error.toResolvingLocation(), context.config.nullableAnnot), - "PASSING_NULLABLE", - false)) + "PASSING_NULLABLE")) .collect(Collectors.toSet()); } } diff --git a/annotator-core/src/main/java/edu/ucr/cs/riple/core/registries/index/Fix.java b/annotator-core/src/main/java/edu/ucr/cs/riple/core/registries/index/Fix.java index f74ce03d6..1e365a984 100644 --- a/annotator-core/src/main/java/edu/ucr/cs/riple/core/registries/index/Fix.java +++ b/annotator-core/src/main/java/edu/ucr/cs/riple/core/registries/index/Fix.java @@ -50,25 +50,18 @@ public class Fix { public final Set changes; /** Reasons this fix is suggested by NullAway in string. */ public final ImmutableSet reasons; - /** - * If true, the fix is suggested due to an error in the target module, false if the fix is - * suggested due to error in downstream dependencies. - */ - public boolean fixSourceIsInTarget; - public Fix(AddAnnotation change, String reason, boolean fixSourceIsInTarget) { - this(change, ImmutableSet.of(reason), fixSourceIsInTarget); + public Fix(AddAnnotation change, String reason) { + this(change, ImmutableSet.of(reason)); } - public Fix(AddAnnotation change, ImmutableSet reasons, boolean fixSourceIsInTarget) { - this(ImmutableSet.of(change), reasons, fixSourceIsInTarget); + public Fix(AddAnnotation change, ImmutableSet reasons) { + this(ImmutableSet.of(change), reasons); } - public Fix( - Set changes, ImmutableSet reasons, boolean fixSourceIsInTarget) { - this.changes = changes; + public Fix(ImmutableSet change, ImmutableSet reasons) { + this.changes = change; this.reasons = reasons; - this.fixSourceIsInTarget = fixSourceIsInTarget; } /** diff --git a/annotator-core/src/main/java/edu/ucr/cs/riple/core/registries/region/generatedcode/LombokHandler.java b/annotator-core/src/main/java/edu/ucr/cs/riple/core/registries/region/generatedcode/LombokHandler.java index 21277face..3991bff15 100644 --- a/annotator-core/src/main/java/edu/ucr/cs/riple/core/registries/region/generatedcode/LombokHandler.java +++ b/annotator-core/src/main/java/edu/ucr/cs/riple/core/registries/region/generatedcode/LombokHandler.java @@ -120,8 +120,7 @@ public ImmutableSet extendForGeneratedFixes(Set fixes) { new Fix( new AddMarkerAnnotation( getterMethod.location, change.getAnnotationName().fullName), - fix.reasons, - fix.fixSourceIsInTarget)); + fix.reasons)); } }))); return builder.build(); diff --git a/annotator-core/src/test/java/edu/ucr/cs/riple/core/tools/TError.java b/annotator-core/src/test/java/edu/ucr/cs/riple/core/tools/TError.java index 7ac7b88d3..f4f963e52 100644 --- a/annotator-core/src/test/java/edu/ucr/cs/riple/core/tools/TError.java +++ b/annotator-core/src/test/java/edu/ucr/cs/riple/core/tools/TError.java @@ -47,7 +47,7 @@ public TError(Location location) { @Override protected Set computeFixesFromAnnotations(Set annotations) { return annotations.stream() - .map(addAnnotation -> new Fix(addAnnotation, ImmutableSet.of(messageType), true)) + .map(addAnnotation -> new Fix(addAnnotation, ImmutableSet.of(messageType))) .collect(Collectors.toSet()); } } diff --git a/annotator-core/src/test/java/edu/ucr/cs/riple/core/tools/TFix.java b/annotator-core/src/test/java/edu/ucr/cs/riple/core/tools/TFix.java index f21bd9dab..17caf70c0 100644 --- a/annotator-core/src/test/java/edu/ucr/cs/riple/core/tools/TFix.java +++ b/annotator-core/src/test/java/edu/ucr/cs/riple/core/tools/TFix.java @@ -36,6 +36,6 @@ public class TFix extends Fix { public TFix(Location location) { - super(new DefaultAnnotation(location), ImmutableSet.of(), true); + super(new DefaultAnnotation(location), ImmutableSet.of()); } } diff --git a/annotator-core/src/test/java/edu/ucr/cs/riple/core/tools/TReport.java b/annotator-core/src/test/java/edu/ucr/cs/riple/core/tools/TReport.java index efde82309..918012b11 100644 --- a/annotator-core/src/test/java/edu/ucr/cs/riple/core/tools/TReport.java +++ b/annotator-core/src/test/java/edu/ucr/cs/riple/core/tools/TReport.java @@ -50,8 +50,7 @@ public TReport(Location root, int effect) { public TReport(Location root, int effect, Tag tag) { super( - new Fix( - new AddMarkerAnnotation(root, "javax.annotation.Nullable"), ImmutableSet.of(), true), + new Fix(new AddMarkerAnnotation(root, "javax.annotation.Nullable"), ImmutableSet.of()), effect); this.expectedValue = effect; if (tag != null) { diff --git a/gradle/dependencies.gradle b/gradle/dependencies.gradle index c2e422942..218205a98 100644 --- a/gradle/dependencies.gradle +++ b/gradle/dependencies.gradle @@ -35,7 +35,7 @@ def versions = [ errorProne : defaultErrorProneVersion, errorProneApi : project.hasProperty("epApiVersion") ? epApiVersion : oldestErrorProneApi, autoService : "1.0-rc7", - javaparser : "3.26.0", + javaparser : "3.26.2", json : "1.1.1", guava : "31.0.1-jre", cli : "1.5.0", diff --git a/injector/src/main/java/edu/ucr/cs/riple/injector/Injector.java b/injector/src/main/java/edu/ucr/cs/riple/injector/Injector.java index d3eb9d7b5..0d417e19f 100644 --- a/injector/src/main/java/edu/ucr/cs/riple/injector/Injector.java +++ b/injector/src/main/java/edu/ucr/cs/riple/injector/Injector.java @@ -24,6 +24,7 @@ import static java.util.stream.Collectors.groupingBy; +import com.github.javaparser.ParseProblemException; import com.github.javaparser.ParserConfiguration; import com.github.javaparser.StaticJavaParser; import com.github.javaparser.ast.CompilationUnit; @@ -33,6 +34,7 @@ import edu.ucr.cs.riple.injector.changes.AnnotationChange; import edu.ucr.cs.riple.injector.changes.ChangeVisitor; import edu.ucr.cs.riple.injector.changes.RemoveAnnotation; +import edu.ucr.cs.riple.injector.exceptions.ParseException; import edu.ucr.cs.riple.injector.modifications.Modification; import edu.ucr.cs.riple.injector.offsets.FileOffsetStore; import java.io.IOException; @@ -171,6 +173,9 @@ public static CompilationUnit parse( StaticJavaParser.setConfiguration(parserConfiguration); try { return StaticJavaParser.parse(path); + } catch (ParseProblemException e) { + // The original exception is not useful for the user. We should provide a more informative one + throw new ParseException(path, e); } catch (NoSuchFileException e) { return null; } catch (IOException e) { diff --git a/injector/src/main/java/edu/ucr/cs/riple/injector/exceptions/ParseException.java b/injector/src/main/java/edu/ucr/cs/riple/injector/exceptions/ParseException.java new file mode 100644 index 000000000..c01f8c054 --- /dev/null +++ b/injector/src/main/java/edu/ucr/cs/riple/injector/exceptions/ParseException.java @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2024 University of California, Riverside. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +package edu.ucr.cs.riple.injector.exceptions; + +import com.github.javaparser.ParseProblemException; +import java.nio.file.Path; + +/** + * Exception indicating that an error occurred while parsing a source file. + * + *

This serves as a wrapper for the {@link ParseProblemException} class, providing a more concise + * representation of the underlying issue. + */ +public class ParseException extends RuntimeException { + + public ParseException(Path path, ParseProblemException exception) { + super(retrieveExceptionMessage(path, exception), exception); + } + + private static String retrieveExceptionMessage(Path path, ParseProblemException e) { + String message = e.getMessage(); + // If the message contains the stack trace, we should remove it. It does not contain any useful + // information. + int index = message.indexOf("Problem stacktrace :"); + message = index == -1 ? message : message.substring(0, index); + return "javaparser was not able to parse file at: " + path + "\nParse problem:" + message; + } +}