Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issues Compiling with Checker Framework on Minimized ASHE Classes #41

Closed
jonathan-m-phillips opened this issue Nov 13, 2023 · 4 comments
Assignees

Comments

@jonathan-m-phillips
Copy link
Collaborator

jonathan-m-phillips commented Nov 13, 2023

I am encountering compilation errors with the Checker Framework when minimizing classes from the ASHE project, specifically the ASHE#run(String, String, String) method. The minimization process seems to disrupt the dependencies within the project, particularly when the target class relies on other internal classes.

Working Example

Arguments

NOTE: The arguments are different than the main branch on GitHub. The directory has changed on my local environment, which is why the typical would not use edu.njit.jerse.ashe.ASHE#run(String, String, String), but rather edu.njit.jerse.ASHE#run(String, String, String).
I used the following arguments for the Specimin minimization process:

--args=--outputDirectory "my/temp/dir" --root "my/root/to/ASHE_Automated-Software-Hardening-for-Entrypoints/src/main/java" --targetFile "edu/njit/jerse/ashe/ASHE.java" --targetMethod "edu.njit.jerse.ashe.ASHE#run(String, String, String)"

Relevant Code Snippet from ASHE.java

public class ASHE {

    private static final Logger LOGGER = LogManager.getLogger(ASHE.class);

    public void run(String root, String targetFile, String targetMethod) throws IOException, ExecutionException, InterruptedException, TimeoutException {
        JavaCodeCorrector corrector = new JavaCodeCorrector();
        String speciminTempDir = corrector.minimizeTargetFile(root, targetFile, targetMethod);
        final String sourceFilePath = speciminTempDir + "/" + targetFile;
        boolean errorsReplacedInTargetFile = corrector.fixTargetFileErrorsWithGPT(sourceFilePath, targetMethod);
        if (!errorsReplacedInTargetFile) {
            if (corrector.checkedFileError(sourceFilePath).isEmpty()) {
                return;
            } else {
                throw new RuntimeException("Errors were not replaced with GPT response.");
            }
        }
        String methodName = JavaCodeParser.extractMethodName(targetMethod);
        String originalFilePath = root + "/" + targetFile;
        boolean isOriginalMethodReplaced = MethodReplacementService.replaceOriginalTargetMethod(sourceFilePath, originalFilePath, methodName);
        if (!isOriginalMethodReplaced) {
            throw new RuntimeException("Original method was not replaced.");
        }
    }
}

Exception Observed

During the compilation with Checker Framework after minimization, the following compilation errors were observed (example paths are replaced with generic ones for privacy):

21:27:40.199 [main] INFO edu.njit.jerse.ashe.services.CheckerFrameworkCompiler - Attempting to compile Java class using Checker Framework: /my/temp/dir/edu/njit/jerse/ashe/ASHE.java
21:27:40.199 [main] INFO edu.njit.jerse.ashe.services.CheckerFrameworkCompiler - Constructing compilation command for Java class: /my/temp/dir/edu/njit/jerse/ashe/ASHE.java
21:27:41.265 [main] WARN edu.njit.jerse.ashe.services.CheckerFrameworkCompiler - Compilation error for classPath /my/temp/dir/edu/njit/jerse/ashe/ASHE.java:
error: package edu.njit.jerse.ashe.services does not exist
import edu.njit.jerse.ashe.services.MethodReplacementService;
^
/my/temp/dir/edu/njit/jerse/ashe/ASHE.java:4: error: package edu.njit.jerse.ashe.utils does not exist
import edu.njit.jerse.ashe.utils.JavaCodeCorrector;
^
/my/temp/dir/edu/njit/jerse/ashe/ASHE.java:5: error: package edu.njit.jerse.ashe.utils does not exist
import edu.njit.jerse.ashe.utils.JavaCodeParser;
^
/my/temp/dir/edu/njit/jerse/ashe/ASHE.java:6: error: package org.apache.logging.log4j does not exist
import org.apache.logging.log4j.LogManager;
^
/my/temp/dir/edu/njit/jerse/ashe/ASHE.java:7: error: package org.apache.logging.log4j does not exist
import org.apache.logging.log4j.Logger;
^
/my/temp/dir/edu/njit/jerse/ashe/ASHE.java:14: error: cannot find symbol
private static final Logger LOGGER = LogManager.getLogger(ASHE.class);
^
symbol: class Logger
location: class ASHE
/my/temp/dir/edu/njit/jerse/ashe/ASHE.java:14: error: cannot find symbol
private static final Logger LOGGER = LogManager.getLogger(ASHE.class);
^
symbol: variable LogManager
location: class ASHE
/my/temp/dir/edu/njit/jerse/ashe/ASHE.java:17: error: cannot find symbol
JavaCodeCorrector corrector = new JavaCodeCorrector();
^
symbol: class JavaCodeCorrector
location: class ASHE
/my/temp/dir/edu/njit/jerse/ashe/ASHE.java:17: error: cannot find symbol
JavaCodeCorrector corrector = new JavaCodeCorrector();
^
symbol: class JavaCodeCorrector
location: class ASHE
/my/temp/dir/edu/njit/jerse/ashe/ASHE.java:28: error: cannot find symbol
String methodName = JavaCodeParser.extractMethodName(targetMethod);
^
symbol: variable JavaCodeParser
location: class ASHE
/my/temp/dir/edu/njit/jerse/ashe/ASHE.java:30: error: cannot find symbol
boolean isOriginalMethodReplaced = MethodReplacementService.replaceOriginalTargetMethod(sourceFilePath, originalFilePath, methodName);
^
symbol: variable MethodReplacementService
location: class ASHE

Suspected Issue

It appears that the Specimin minimization process might not be correctly handling or preserving the project's internal dependencies, leading to compilation failures. The issue is particularly evident when the minimized class is tightly coupled with other internal components of the project.

@LoiNguyenCS
Copy link
Collaborator

Hi there, I'm going to experiment with the project and will keep you updated on my progress.

@LoiNguyenCS
Copy link
Collaborator

Partially solved by #58.

@jonathan-m-phillips
Copy link
Collaborator Author

Ping - should this issue be closed? It appears it was partially fixed by #58 and then more work was done on #59 that was merged.

@LoiNguyenCS
Copy link
Collaborator

Thank you for reminding.

Fixed by #58 and #59.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants