From 9b533330d2fe063577c134a52e8aec8f13e6e021 Mon Sep 17 00:00:00 2001 From: Nima Karimipour Date: Thu, 3 Oct 2024 12:07:17 -0500 Subject: [PATCH 1/4] fix ci deprecation error (#244) This PR resolves [issue](https://github.blog/changelog/2024-02-13-deprecation-notice-v1-and-v2-of-the-artifact-actions/) that causes to CI for task `build-with-upload`. --- .github/workflows/continuous-integration.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index fa44870f2..bcf45b8c0 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -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' From 56410a62790a96d2f3f7a211efd83f61d38c9722 Mon Sep 17 00:00:00 2001 From: Nima Karimipour Date: Thu, 3 Oct 2024 12:44:24 -0500 Subject: [PATCH 2/4] Upgrade action versions from v2 to v4 (#245) This PR resolves [issue](https://github.blog/changelog/2024-02-13-deprecation-notice-v1-and-v2-of-the-artifact-actions/) and upgrades all actions versions from `v2` to `v4`. --- .github/workflows/continuous-integration.yml | 26 ++++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index bcf45b8c0..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' @@ -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' From 83fcf3102ee9bb9f9b3fab600a6c7dc86c03da82 Mon Sep 17 00:00:00 2001 From: Nima Karimipour Date: Thu, 3 Oct 2024 13:11:12 -0500 Subject: [PATCH 3/4] Upgrade javaparser and enhance the fail message for parse exceptions (#241) This PR upgrades the javaparser library to version `3.26.2` and enhances the fail message for parse exceptions, providing more context and clarity. Before this change, a parse exception would display a message like the following, which lacks sufficient context: ``` Exception in thread "main" com.github.javaparser.ParseProblemException: (line 699,col 20) Parse error. Found ":", expected "(" Problem stacktrace : com.github.javaparser.GeneratedJavaParser.generateParseException(GeneratedJavaParser.java:14419) com.github.javaparser.GeneratedJavaParser.jj_consume_token(GeneratedJavaParser.java:14264) com.github.javaparser.GeneratedJavaParser.PatternList(GeneratedJavaParser.java:4128) com.github.javaparser.GeneratedJavaParser.RecordPatternExpression(GeneratedJavaParser.java:4114) com.github.javaparser.GeneratedJavaParser.PatternExpression(GeneratedJavaParser.java:4069) com.github.javaparser.GeneratedJavaParser.SwitchEntry(GeneratedJavaParser.java:6491) com.github.javaparser.GeneratedJavaParser.SwitchStatement(GeneratedJavaParser.java:6381) com.github.javaparser.GeneratedJavaParser.Statement(GeneratedJavaParser.java:5828) com.github.javaparser.GeneratedJavaParser.BlockStatement(GeneratedJavaParser.java:6079) com.github.javaparser.GeneratedJavaParser.Statements(GeneratedJavaParser.java:2811) com.github.javaparser.GeneratedJavaParser.Block(GeneratedJavaParser.java:5955) com.github.javaparser.GeneratedJavaParser.MethodDeclaration(GeneratedJavaParser.java:2201) com.github.javaparser.GeneratedJavaParser.ClassOrInterfaceBodyDeclaration(GeneratedJavaParser.java:1796) com.github.javaparser.GeneratedJavaParser.ClassOrInterfaceBody(GeneratedJavaParser.java:1286) com.github.javaparser.GeneratedJavaParser.ClassOrInterfaceDeclaration(GeneratedJavaParser.java:538) com.github.javaparser.GeneratedJavaParser.CompilationUnit(GeneratedJavaParser.java:156) com.github.javaparser.JavaParser.parse(JavaParser.java:125) com.github.javaparser.JavaParser.parse(JavaParser.java:231) com.github.javaparser.JavaParserAdapter.parse(JavaParserAdapter.java:99) com.github.javaparser.StaticJavaParser.parse(StaticJavaParser.java:173) edu.ucr.cs.riple.injector.Injector.parse(Injector.java:173) edu.ucr.cs.riple.core.registries.field.FieldRegistry$1.build(FieldRegistry.java:115) edu.ucr.cs.riple.core.registries.field.FieldRegistry$1.build(FieldRegistry.java:97) edu.ucr.cs.riple.core.registries.Registry.populateContent(Registry.java:122) edu.ucr.cs.riple.core.registries.Registry.lambda$new$0(Registry.java:91) java.base/java.lang.Iterable.forEach(Iterable.java:75) edu.ucr.cs.riple.core.registries.Registry.(Registry.java:88) edu.ucr.cs.riple.core.registries.field.FieldRegistry.(FieldRegistry.java:82) edu.ucr.cs.riple.core.module.ModuleInfo.(ModuleInfo.java:94) edu.ucr.cs.riple.core.module.ModuleInfo.(ModuleInfo.java:75) edu.ucr.cs.riple.core.Context.(Context.java:78) edu.ucr.cs.riple.core.Annotator.(Annotator.java:63) edu.ucr.cs.riple.core.Main.main(Main.java:45) (line 709,col 14) Parse error. Found "case", expected "}" ``` With this update, the error message now includes the file path, making it easier to locate the issue: ``` javaparser was not able to parse file at: /path_to_Foojava Parse problem: (line 699,col 20) Parse error. Found ":", expected "(" ``` This change involves both the library upgrade and an improvement to the error message but both are included in this single PR rather than separated due to the small scope of changes. --- gradle/dependencies.gradle | 2 +- .../edu/ucr/cs/riple/injector/Injector.java | 5 ++ .../injector/exceptions/ParseException.java | 48 +++++++++++++++++++ 3 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 injector/src/main/java/edu/ucr/cs/riple/injector/exceptions/ParseException.java 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; + } +} From 7cfb5c62f957219857e5eec8d8654d9495885c9c Mon Sep 17 00:00:00 2001 From: Nima Karimipour Date: Thu, 3 Oct 2024 13:11:34 -0500 Subject: [PATCH 4/4] clean up fixIsSource flag from fix class (#243) This PR removes the unused flag `fixIsSource` which indicates if the fix is suggested from an error in the source code of target or downstream dependency. This flag is not used in the latest logic anymore and is redundant. This PR removes this flag from the fix class declaration. --- .../cache/downstream/DownstreamImpactCacheImpl.java | 4 +--- .../cs/riple/core/checkers/nullaway/NullAway.java | 6 ++---- .../ucr/cs/riple/core/evaluators/graph/Node.java | 1 - .../processors/AbstractConflictGraphProcessor.java | 3 +-- .../ucr/cs/riple/core/registries/index/Error.java | 4 +--- .../edu/ucr/cs/riple/core/registries/index/Fix.java | 13 +++---------- .../region/generatedcode/LombokHandler.java | 3 +-- .../test/java/edu/ucr/cs/riple/core/tools/TFix.java | 2 +- .../java/edu/ucr/cs/riple/core/tools/TReport.java | 3 +-- 9 files changed, 11 insertions(+), 28 deletions(-) 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 b9392acaf..f74d493aa 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 98b503419..284a9723b 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 @@ -130,8 +130,7 @@ private NullAwayError deserializeErrorFromTSVLine(ModuleInfo moduleInfo, String Fix resolvingFix = nonnullTarget == null ? null - : new Fix( - new AddMarkerAnnotation(nonnullTarget, config.nullableAnnot), errorType, true); + : new Fix(new AddMarkerAnnotation(nonnullTarget, config.nullableAnnot), errorType); return createError( errorType, errorMessage, @@ -201,8 +200,7 @@ protected ImmutableSet generateFixesForUninitializedFields( return new Fix( new AddMarkerAnnotation( extendVariableList(locationOnField, module), config.nullableAnnot), - NullAwayError.METHOD_INITIALIZER_ERROR, - true); + NullAwayError.METHOD_INITIALIZER_ERROR); }) .filter(Objects::nonNull) .collect(ImmutableSet.toImmutableSet()); 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 dd0da2b13..52cbfd5ca 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 @@ -186,7 +186,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 9ec874c52..6a877e491 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 @@ -81,8 +81,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/Error.java b/annotator-core/src/main/java/edu/ucr/cs/riple/core/registries/index/Error.java index 7e24315d6..9ead2c131 100644 --- a/annotator-core/src/main/java/edu/ucr/cs/riple/core/registries/index/Error.java +++ b/annotator-core/src/main/java/edu/ucr/cs/riple/core/registries/index/Error.java @@ -223,9 +223,7 @@ public static ImmutableSet getResolvingFixesOfErrors( for (Fix key : fixReasonsMap.keySet()) { // To avoid mutating fixes stored in the given collection, we create new instances. // which contain the full set of reasons. - builder.add( - new Fix( - key.change, ImmutableSet.copyOf(fixReasonsMap.get(key)), key.fixSourceIsInTarget)); + builder.add(new Fix(key.change, ImmutableSet.copyOf(fixReasonsMap.get(key)))); } return builder.build(); } 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 11ca6d52b..56a12bf63 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 @@ -48,20 +48,13 @@ public class Fix { /** 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) { + public Fix(AddAnnotation change, ImmutableSet reasons) { this.change = 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 35ac34e9b..84ce00371 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/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) {