ucr-riple / NullAwayAnnotator

A tool to help adapting code bases to NullAway type system.
MIT License
13 stars 6 forks source link

class_info.tsv not being generated and found #256

Closed droidchef closed 4 weeks ago

droidchef commented 1 month ago

Describe the bug I have NullAway configured on my module and getting some errors reported when I build it. Now I am trying to configure the annotator to annotate the objects in that module. When the I run the annotator jar, I get an exception stating "class_info.tsv" file is not found.

To Reproduce Apply NullAway and NullAwayAnnotator to the gradle module and run the annotator jar. Here is how my target gradle module is configured:

plugins {
    id ("net.ltgt.errorprone") version "2.0.2"
}
import net.ltgt.gradle.errorprone.CheckSeverity
import com.android.build.gradle.api.BaseVariant

apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'

android {
 // blah blah blah
}

repositories {
    mavenCentral()
}

dependencies {
    errorprone "com.google.errorprone:error_prone_core:2.4.0"
    annotationProcessor "edu.ucr.cs.riple.annotator:annotator-scanner:1.3.6"
    annotationProcessor "com.uber.nullaway:nullaway:0.10.11"
    errorproneJavac "com.google.errorprone:javac:9+181-r4173-1"
}

tasks.withType(JavaCompile) {
    options.errorprone.disableAllChecks = true
    options.errorprone {
        check("NullAway", CheckSeverity.ERROR)
        option("NullAway:AnnotatedPackages", "com.bytedance")
        option("NullAway:SerializeFixMetadata", true)
        option("NullAway:FixSerializationConfigPath", "/Users/bytedance/workspace/trial/NullAway/config.xml")
        check("AnnotatorScanner", CheckSeverity.ERROR)
        option("AnnotatorScanner:ConfigPath", "/Users/bytedance/workspace/trial/NullAway/scanner.xml")
    }
}

Here is my config.json

{
    "BUILD_COMMAND": "cd /Users/bytedance/workspace/TikTok && ./gradlew :smartrouter:build 1>&2",
    "ANNOTATION": {
      "INITIALIZER": "com.example.Initializer",
      "NULLABLE": "org.jetbrains.annotations.Nullable"
    },
    "OUTPUT_DIR": "/Users/bytedance/workspace/trial/NullAway/",
    "CONFIG_PATHS": [
      {
        "NULLAWAY": "config.xml",
        "SCANNER": "scanner.xml"
      }
    ],
    "DEPTH": 1,
    "BAILOUT": true,
    "REDIRECT_BUILD_OUTPUT_TO_STDERR": true
}

Here is my config.xml

<?xml version="1.0" encoding="UTF-8" standalone="no"?><serialization><suggest active="true" enclosing="true"/><fieldInitInfo active="true"/><path>/Users/bytedance/workspace/trial/NullAway/0</path><uuid>7e01f68d-1253-47cc-ad74-89ea512b2602</uuid></serialization>

Here is my scanner.xml

<?xml version="1.0" encoding="UTF-8" standalone="no"?><scanner><method active="true"/><field active="true"/><call active="true"/><class active="true"/><uuid>cb6047a0-23af-412f-bafd-06c7cb60e1d6</uuid><path>/Users/bytedance/workspace/trial/NullAway/0</path><processor><LOMBOK active="true"/></processor><annotations/></scanner>

Expected behavior Expecting the Annotator to provide some annotations either as a diff or in place. I am not sure based on the documentation what is supposed to yield so unable to provide exact response for this section since this is my first time trying out this project.

Stack trace

Exception in thread "main" java.lang.RuntimeException: Error happened while loading content of file: /Users/bytedance/workspace/trial/NullAway/0/class_info.tsv
    at edu.ucr.cs.riple.core.metadata.MetaData.<init>(MetaData.java:69)
    at edu.ucr.cs.riple.core.metadata.field.FieldDeclarationStore.<init>(FieldDeclarationStore.java:58)
    at edu.ucr.cs.riple.core.Annotator.preprocess(Annotator.java:104)
    at edu.ucr.cs.riple.core.Annotator.start(Annotator.java:82)
    at edu.ucr.cs.riple.core.Main.main(Main.java:46)
Caused by: java.nio.file.NoSuchFileException: /Users/bytedance/workspace/trial/NullAway/0/class_info.tsv
    at java.base/sun.nio.fs.UnixException.translateToIOException(UnixException.java:92)
    at java.base/sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:111)
    at java.base/sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:116)
    at java.base/sun.nio.fs.UnixFileSystemProvider.newByteChannel(UnixFileSystemProvider.java:219)
    at java.base/java.nio.file.Files.newByteChannel(Files.java:371)
    at java.base/java.nio.file.Files.newByteChannel(Files.java:422)
    at java.base/java.nio.file.spi.FileSystemProvider.newInputStream(FileSystemProvider.java:420)
    at java.base/java.nio.file.Files.newInputStream(Files.java:156)
    at java.base/java.nio.file.Files.newBufferedReader(Files.java:2839)
    at edu.ucr.cs.riple.core.metadata.MetaData.fillNodes(MetaData.java:108)
    at edu.ucr.cs.riple.core.metadata.MetaData.<init>(MetaData.java:67)
    ... 4 more

OS (please complete the following information):

Would be happy to answer any followup questions and provide more info if that helps you figure out the issue.

I appreciate this project very much and would be grateful for any support I can get to move past this error. 🙏

droidchef commented 1 month ago

@msridhar I was going through some other issues and it looks this issue might be related to an issue you have created https://github.com/ucr-riple/NullAwayAnnotator/issues/237

Why do I think so? Because compilation of the target module/project does fail in this case due to the NullAway complaining about some objects. 🤔 Wondering if there is a workaround you already know about this, just yet?

msridhar commented 1 month ago

@droidchef thanks for all the feedback! I'm at a conference this week along with @nimakarimipour. We should have more time to look in a few days.

droidchef commented 1 month ago

Thanks @msridhar! Looking forward to getting these issues resolved with your and @nimakarimipour's help.

nimakarimipour commented 1 month ago

Hi @droidchef, We're still busy with the conference, but I took a quick look. Based on the configuration in the issue description, it looks like the immediate problem is with the paths in config.json for NULLAWAY and SCANNER. They should be absolute paths instead of relative paths.

For example, this:

"CONFIG_PATHS": [
      {
        "NULLAWAY": "config.xml",
        "SCANNER": "scanner.xml"
      }
]

should be:

"CONFIG_PATHS": [
      {
        "NULLAWAY": "/Users/bytedance/workspace/trial/NullAway/config.xml",
        "SCANNER": "/Users/bytedance/workspace/trial/NullAway/scanner.xml"
      }
]

Let me know if this helps! Sorry for the inconveniences, we will update our docs to clarify these and work on #255.

Also we are planning to remove -p option where you can set configuration inside a json file and instead only work with command lines options.

droidchef commented 4 weeks ago

Thank you @nimakarimipour This recommendation worked! I was able to get annotator to run on my target.

nimakarimipour commented 4 weeks ago

@droidchef Glad it worked 🙂. Closing this issue.