diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md index f2eae21e1..a99739e1f 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -8,22 +8,16 @@ assignees: '' --- **Describe the bug** -A clear and concise description of what the bug is. +A clear and concise description of what the bug is and the used version of the software. -**To Reproduce** +**To Reproduce** [OPTIONAL] Steps to reproduce the behavior: (Prefer a code snippet) -**Expected behavior** +**Expected behavior** [OPTIONAL] A clear and concise description of what you expected to happen. -**Stack trace** +**Stack trace** [OPTIONAL] If applicable, add stack trace of the exception below. -**OS (please complete the following information):** - - OS: [e.g. iOS] - - Version [e.g. 22] - - Annotator Version [e.g. v1.3.1-LOCAL] - - -**Additional context** +**Additional context** [OPTIONAL] Add any other context about the problem here. diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md index 021458556..49ca66514 100644 --- a/.github/ISSUE_TEMPLATE/feature_request.md +++ b/.github/ISSUE_TEMPLATE/feature_request.md @@ -10,11 +10,8 @@ assignees: '' **Is your feature request related to a problem? Please describe.** A clear and concise description of what the problem is. -**Describe the solution you'd like** +**Describe the solution you'd like** [OPTIONAL] A clear and concise description of what you want to happen. -**Describe alternatives you've considered** -A clear and concise description of any alternative solutions or features you've considered. - -**Additional context** +**Additional context** [OPTIONAL] Add any other context or screenshots about the feature request here. diff --git a/.github/ISSUE_TEMPLATE/todo.md b/.github/ISSUE_TEMPLATE/todo.md deleted file mode 100644 index 30c90e6d2..000000000 --- a/.github/ISSUE_TEMPLATE/todo.md +++ /dev/null @@ -1,17 +0,0 @@ ---- -name: TODO -about: Create a report to help us improve -title: '' -labels: '' -assignees: '' - ---- - -**Describe the task** -A clear and concise description of what the task is. - -**Expected behavior** -A clear and concise description of what you expected to happen. - -**Additional context** -Add any other context about the task here. diff --git a/README.md b/README.md index 73ac1ab09..b41004c0e 100644 --- a/README.md +++ b/README.md @@ -3,9 +3,15 @@ `NullAwayAnnotator`, or simply `Annotator`, is a tool that automatically infers nullability types in the given source code and injects the corresponding annotations to pass [NullAway](https://github.com/uber/NullAway) checks. -Applying NullAway to build systems requires manual effort in annotating the source code. Even if the code is free of nullability errors, annotations are still needed to pass NullAway checks. A tool that can automatically infer types in the source code and inject the corresponding annotations to pass NullAway checks can significantly reduce the effort of integrating NullAway into build systems. +Applying NullAway to build systems requires manual effort in annotating the source code. +Even if the code is free of nullability errors, annotations are still needed to pass NullAway checks. +A tool that can automatically infer types in the source code +and inject the corresponding annotations to pass NullAway checks can significantly reduce the effort +of integrating NullAway into build systems. -`Annotator` minimizes the number of reported NullAway errors by inferring nullability types of elements in the source code and injecting the corresponding annotations. For errors that are not resolvable with any annotations, Annotator injects appropriate suppression annotations. The final output of Annotator is a source code that passes NullAway checks with no remaining errors. +`Annotator` minimizes the number of reported NullAway errors by inferring nullability types of elements in the source code and injecting the corresponding annotations. +For errors that are not resolvable with any annotations, Annotator injects appropriate suppression annotations. +The final output of Annotator is a source code that passes NullAway checks with no remaining errors. ## Code Example @@ -38,7 +44,8 @@ class Test{ } ``` -`Annotator` can infer the nullable types in the code above and inject the corresponding annotations. For unresolved errors, suppression annotations are injected. +`Annotator` can infer the nullable types in the code above and inject the corresponding annotations. +For unresolved errors, suppression annotations are injected. The output below shows the result of running `Annotator` on the code above. ```java @@ -75,7 +82,8 @@ class Test{ `Annotator` propagates the effects of a change throughout the entire module and injects several follow-up annotations to fully resolve a specific warning. It is also capable of processing modules within monorepos, taking into account the modules public APIs and the impacts of annotations on downstream dependencies for improved results. ## Installation -We ship Annotator on [Maven](https://repo.maven.apache.org/maven2/edu/ucr/cs/riple/annotator/), as a JAR. You can find the artifact information below - +We ship [Annotator](https://repo.maven.apache.org/maven2/edu/ucr/cs/riple/annotator/) on [Maven](https://repo.maven.apache.org/) as a JAR. +You can find the artifact information below: ``` GROUP: edu.ucr.cs.riple.annotator ID: annotator-core @@ -86,71 +94,74 @@ ID: annotator-scanner This sections describes how to run `Annotator` on any project. -- ### Requirements for the Target Project +### Requirements for the Target Project - #### Dependencies - - `NullAway` checker must be activated with version >= `0.10.10` - - `AnnotatorScanner` checker must be activated with version >= `1.3.6`, see more about `AnnotatorScanner` [here](../type-annotator-scanner/README.md). +#### Dependencies +- `NullAway` checker must be activated with a version >= `0.10.10` +- `AnnotatorScanner` checker must be activated with a version >= `1.3.6`, see more about `AnnotatorScanner` [here](../type-annotator-scanner/README.md). - #### Error Prone Flags - Since Nullaway is built as a plugin for [Error Prone](https://github.com/google/error-prone), we need to set the following flags in our build.gradle, - ``` +#### Error Prone Flags +Since Nullaway is built as a plugin for [Error Prone](https://github.com/google/error-prone), we need to set the following flags in our build.gradle, +``` "-Xep:NullAway:ERROR", // to activate NullAway "-XepOpt:NullAway:SerializeFixMetadata=true", "-XepOpt:NullAway:FixSerializationConfigPath=path_to_nullaway_config.xml", "-Xep:AnnotatorScanner:ERROR", // to activate Annotator AnnotatorScanner "-XepOpt:AnnotatorScanner:ConfigPath=path_to_scanner_config.xml", - ``` - - - - - The following code snippet demonstrates how to configure the `JavaCompile` tasks in your `build.gradle` to use NullAway as a plugin for [Error Prone](https://github.com/google/error-prone): - ```groovy - dependencies { - annotationProcessor 'edu.ucr.cs.riple.annotator:annotator-scanner:1.3.6' - annotationProcessor "com.uber.nullaway:nullaway:0.10.10" - errorprone "com.google.errorprone:error_prone_core:2.4.0" - errorproneJavac "com.google.errorprone:javac:9+181-r4173-1" - //All other target project dependencies - } - - - tasks.withType(JavaCompile) { - // remove the if condition if you want to run NullAway on test code - if (!name.toLowerCase().contains("test")) { - options.errorprone { - check("NullAway", CheckSeverity.ERROR) - check("AnnotatorScanner", CheckSeverity.ERROR) - option("NullAway:AnnotatedPackages", "org.example") - option("NullAway:SerializeFixMetadata", "true") - option("NullAway:FixSerializationConfigPath", "path_to/nullaway.xml") - option("AnnotatorScanner:ConfigPath", "path_to/scanner.xml") - } - options.compilerArgs << "-Xmaxerrs"<< "100000" - options.compilerArgs << "-Xmaxwarns" << "100000" - } - - } - ``` - `path_to_nullaway_config.xml` and `path_to_scanner_config.xml` are configuration files that **do not need to be created** during the initial project setup. The script will generate these files, facilitating seamless communication between the script and the analysis. At this point, the target project is prepared for the Annotator to process. - - You must provide the Annotator with the paths to `path_to_nullaway_config.xml` and `path_to_scanner_config.xml`. Further details on this process are described in the sections below. - -- ### Running Annotator - `Annotator` necessitates specific flag values for successful execution. You can provide these values through command line arguments. +``` +The following code snippet demonstrates how to configure the `JavaCompile` tasks in your `build.gradle` to use NullAway as a plugin for [Error Prone](https://github.com/google/error-prone): +```groovy +dependencies { + annotationProcessor 'edu.ucr.cs.riple.annotator:annotator-scanner:1.3.6' + annotationProcessor "com.uber.nullaway:nullaway:0.10.10" + errorprone "com.google.errorprone:error_prone_core:2.4.0" + errorproneJavac "com.google.errorprone:javac:9+181-r4173-1" + + // add required annotation dependencies + // Initializer + compileOnly 'com.uber.nullaway:nullaway-annotations:0.10.10' + // Nullable annotations + compileOnly "com.google.code.findbugs:jsr305:3.0.2" + // JSpecify annotations for NullUnmarked + compileOnly "org.jspecify:jspecify:0.3.0" + //All other target project dependencies +} + +tasks.withType(JavaCompile) { + // remove the if condition if you want to run NullAway on test code + if (!name.toLowerCase().contains("test")) { + options.errorprone { + check("NullAway", CheckSeverity.ERROR) + check("AnnotatorScanner", CheckSeverity.ERROR) + option("NullAway:AnnotatedPackages", "org.example") + option("NullAway:SerializeFixMetadata", "true") + option("NullAway:FixSerializationConfigPath", "path_to/nullaway.xml") + option("AnnotatorScanner:ConfigPath", "path_to/scanner.xml") + } + options.compilerArgs << "-Xmaxerrs"<< "100000" + options.compilerArgs << "-Xmaxwarns" << "100000" + } +} +``` +`path_to_nullaway_config.xml` and `path_to_scanner_config.xml` are configuration files that **do not need to be created** during the initial project setup. The script will generate these files, facilitating seamless communication between the script and the analysis. At this point, the target project is prepared for the Annotator to process. + +You must provide the Annotator with the absolute paths to `path_to_nullaway_config.xml` and `path_to_scanner_config.xml`. +Further details on this process are described in the sections below. - To run `Annotator` on the target project `P`, the arguments below **must** be passed to `Annotator`: +### Running Annotator +`Annotator` necessitates specific flag values for successful execution. You can provide these values through command line arguments. - | Flag | Description | - |------|-------------| - | `-bc,--build-command <arg>` | Command to run `NullAway` on target `P` enclosed in **""**. Please note that this command should be executable from any directory (e.g., `"cd /Absolute/Path/To/P && ./build"`). | - | `-i,--initializer <arg>` | Fully qualified name of the `@Initializer` annotation. | - | `-d,--dir <arg>` | Directory where all outputs of `AnnotatorScanner` and `NullAway` are serialized. | - | `-cp, --config-paths` | Path to a TSV file containing values defined in [Error Prone](./README.md#Error-Prone-Flags) config paths given in the format: (`path_to_nullaway_config.xml \t path_to_scanner_config`). | - | `-cn, --checker-name` | Checker name to be used for the analysis. (use NULLAWAY to request inference for NullAway.)| +To run `Annotator` on the target project `P`, the arguments below **must** be passed to `Annotator`: +| Flag | Description | +|------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| `-bc,--build-command <arg>` | Command to run `NullAway` on target `P` enclosed in **""**. Please note that this command should be executable from any directory (e.g., `"cd /Absolute/Path/To/P && ./build"`). | +| `-i,--initializer <arg>` | Fully qualified name of the `@Initializer` annotation. | +| `-d,--dir <arg>` | Absolute path of an **Empty** Directory where all outputs of `AnnotatorScanner` and `NullAway` are serialized. | +| `-cp, --config-paths` | Path to a TSV file containing value of config paths given in the format: (`path_to_nullaway_config.xml \t path_to_scanner_config`). | +| `-cn, --checker-name` | Checker name to be used for the analysis. (use `NULLAWAY` to request inference for NullAway.) | +| `-sre, --supress-remaning-errors` <arg> | Suppress remaining errors in the code with the given `@NullUnmared` annotation (e.g. `org.jspecify.annotations.NullUnmarked`) | By default, `Annotator` has the configuration below: @@ -176,8 +187,24 @@ To learn more about all the __optional__ arguments, please refer to [OPTIONS.md] Here is a template command you can use to run Annotator from the CLI, using CLI options- ```bash -java -jar ./path/to/annotator-core.jar -d "/path/to/output/directory" -cp "/path/to/config/paths.tsv" -i com.example.Initializer -bc "cd /path/to/targetProject && ./gradlew build -x test" +curl -O https://repo.maven.apache.org/maven2/edu/ucr/cs/riple/annotator/annotator-core/1.3.15/annotator-core-1.3.15.jar +java -jar annotator-core-1.3.15.jar \ + -bc "cd project && command_to_compile_target_project_using_javac" \ + -d "path_to_selected_annotator_out_dir" \ + -n javax.annotation.Nullable \ + -cp sample/annotator-out/paths.tsv \ + -cn NULLAWAY \ + -i com.uber.nullaway.annotations.Initializer \ + -sre org.jspecify.annotations.NullUnmarked +``` + +## Running Annotator on the [example project](#code-example) +The example in this readme is available in module `sample` in this project. +To run Annotator on the example project, you can use the following command: +```bash +./annotator-sample-command.sh ``` +It will run annotator on the sample project and will produce the output shown in this readme. To view descriptions of all flags, simply run the JAR with the `--help` option. diff --git a/annotator-sample-command.sh b/annotator-sample-command.sh new file mode 100755 index 000000000..b2020a9f1 --- /dev/null +++ b/annotator-sample-command.sh @@ -0,0 +1,44 @@ +#!/bin/bash +# +# 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. +# + +# download annotator-core.jar from maven repository +curl -O https://repo.maven.apache.org/maven2/edu/ucr/cs/riple/annotator/annotator-core/1.3.15/annotator-core-1.3.15.jar + +# make an EMPTY directory for the annotator output +annotator_out_dir="$(pwd)/sample/annotator-out" +rm -rvf "$annotator_out_dir" && mkdir -p "$annotator_out_dir" + +# make paths.tsv and add the placed nullaway_config_path and scanner_config_path +scanner_config_path="$(pwd)/sample/annotator-out/scanner.xml" +nullaway_config_path="$(pwd)/sample/annotator-out/nullaway.xml" +echo -e "$nullaway_config_path\t$scanner_config_path" > sample/annotator-out/paths.tsv + +# run the annotator +java -jar annotator-core-1.3.15.jar \ + -bc "cd $(pwd)/sample && ./gradlew compileJava" \ + -d "$annotator_out_dir" \ + -n javax.annotation.Nullable \ + -cp sample/annotator-out/paths.tsv \ + -cn NULLAWAY \ + -i com.uber.nullaway.annotations.Initializer \ + -sre org.jspecify.annotations.NullUnmarked diff --git a/sample/build.gradle b/sample/build.gradle new file mode 100644 index 000000000..df2fe935d --- /dev/null +++ b/sample/build.gradle @@ -0,0 +1,68 @@ +/* + * 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. + */ +import net.ltgt.gradle.errorprone.CheckSeverity + +plugins { + id 'java' + id "net.ltgt.errorprone" version "2.0.1" +} + +repositories { + mavenCentral() +} + +dependencies { + annotationProcessor "com.uber.nullaway:nullaway:0.10.10" + // Add annotator scanner + annotationProcessor "edu.ucr.cs.riple.annotator:annotator-scanner:1.3.15" + + // add required annotation dependencies + // Initializer + compileOnly 'com.uber.nullaway:nullaway-annotations:0.10.10' + // Nullable annotations + compileOnly "com.google.code.findbugs:jsr305:3.0.2" + // JSpecify annotations for NullUnmarked + compileOnly "org.jspecify:jspecify:0.3.0" + + annotationProcessor "com.uber.nullaway:nullaway:0.10.10" + errorprone "com.google.errorprone:error_prone_core:2.4.0" + errorproneJavac "com.google.errorprone:javac:9+181-r4173-1" +} + +def scanner_config_path = "${project.projectDir.absolutePath}/annotator-out/scanner.xml" +def nullaway_config_path = "${project.projectDir.absolutePath}/annotator-out/nullaway.xml" + + +tasks.withType(JavaCompile).configureEach { + if (!name.toLowerCase().contains("test")) { + options.errorprone { + check("NullAway", CheckSeverity.ERROR) + check("AnnotatorScanner", CheckSeverity.ERROR) + option("NullAway:AnnotatedPackages", "edu.ucr.cs.riple") + option("NullAway:SerializeFixMetadata", "true") + option("NullAway:FixSerializationConfigPath", nullaway_config_path) + option("AnnotatorScanner:ConfigPath", scanner_config_path) + } + options.compilerArgs << "-Xmaxerrs" << "100000" + options.compilerArgs << "-Xmaxwarns" << "100000" + } +} diff --git a/sample/gradle/wrapper/gradle-wrapper.jar b/sample/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 000000000..2c3521197 Binary files /dev/null and b/sample/gradle/wrapper/gradle-wrapper.jar differ diff --git a/sample/gradle/wrapper/gradle-wrapper.properties b/sample/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 000000000..09523c0e5 --- /dev/null +++ b/sample/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,7 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-bin.zip +networkTimeout=10000 +validateDistributionUrl=true +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/sample/gradlew b/sample/gradlew new file mode 100755 index 000000000..f5feea6d6 --- /dev/null +++ b/sample/gradlew @@ -0,0 +1,252 @@ +#!/bin/sh + +# +# Copyright © 2015-2021 the original authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# SPDX-License-Identifier: Apache-2.0 +# + +############################################################################## +# +# Gradle start up script for POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh Gradle +# +# Busybox and similar reduced shells will NOT work, because this script +# requires all of these POSIX shell features: +# * functions; +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# Darwin, MinGW, and NonStop. +# +# (3) This script is generated from the Groovy template +# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# within the Gradle project. +# +# You can find Gradle at https://github.com/gradle/gradle/. +# +############################################################################## + +# Attempt to set APP_HOME + +# Resolve links: $0 may be a link +app_path=$0 + +# Need this for daisy-chained symlinks. +while + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + [ -h "$app_path" ] +do + ls=$( ls -ld "$app_path" ) + link=${ls#*' -> '} + case $link in #( + /*) app_path=$link ;; #( + *) app_path=$APP_HOME$link ;; + esac +done + +# This is normally unused +# shellcheck disable=SC2034 +APP_BASE_NAME=${0##*/} +# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) +APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s +' "$PWD" ) || exit + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD=maximum + +warn () { + echo "$*" +} >&2 + +die () { + echo + echo "$*" + echo + exit 1 +} >&2 + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "$( uname )" in #( + CYGWIN* ) cygwin=true ;; #( + Darwin* ) darwin=true ;; #( + MSYS* | MINGW* ) msys=true ;; #( + NONSTOP* ) nonstop=true ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD=$JAVA_HOME/jre/sh/java + else + JAVACMD=$JAVA_HOME/bin/java + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD=java + if ! command -v java >/dev/null 2>&1 + then + die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +fi + +# Increase the maximum file descriptors if we can. +if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then + case $MAX_FD in #( + max*) + # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC2039,SC3045 + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC2039,SC3045 + ulimit -n "$MAX_FD" || + warn "Could not set maximum file descriptor limit to $MAX_FD" + esac +fi + +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. + +# For Cygwin or MSYS, switch paths to Windows format before running java +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) + + # Now convert the arguments - kludge to limit ourselves to /bin/sh + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) + fi + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg + done +fi + + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Collect all arguments for the java command: +# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments, +# and any embedded shellness will be escaped. +# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be +# treated as '${Hostname}' itself on the command line. + +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -classpath "$CLASSPATH" \ + org.gradle.wrapper.GradleWrapperMain \ + "$@" + +# Stop when "xargs" is not available. +if ! command -v xargs >/dev/null 2>&1 +then + die "xargs is not available" +fi + +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# + +eval "set -- $( + printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' + )" '"$@"' + +exec "$JAVACMD" "$@" diff --git a/sample/settings.gradle b/sample/settings.gradle new file mode 100644 index 000000000..ca10c1fee --- /dev/null +++ b/sample/settings.gradle @@ -0,0 +1,25 @@ +/* + * MIT License + * + * Copyright (c) 2024 Nima Karimipour + * + * 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. + */ + +rootProject.name = 'sample' diff --git a/sample/src/main/java/edu/ucr/cs/riple/annotator/sample/Test.java b/sample/src/main/java/edu/ucr/cs/riple/annotator/sample/Test.java new file mode 100644 index 000000000..2dbf12aa1 --- /dev/null +++ b/sample/src/main/java/edu/ucr/cs/riple/annotator/sample/Test.java @@ -0,0 +1,50 @@ +/* + * MIT License + * + * Copyright (c) 2024 Nima Karimipour + * + * 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.annotator.sample; + +public class Test { + Object f1 = null; + Object f2 = null; + Object f3 = null; + Object f4 = null; + Object f5 = f4; + Object f6 = new Object(); + + String m1() { + return f1 != null ? f1.toString() : f2.toString() + f6.toString(); + } + + int m2() { + return f3 != null ? f3.hashCode() : f2.hashCode() + f6.hashCode(); + } + + Object m3() { + return f5; + } + + void m4() { + f6 = null; + } +}