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

Disable JarInfer handler by default #261

Merged
merged 2 commits into from Dec 3, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
48 changes: 48 additions & 0 deletions jar-infer/nullaway-integration-test/build.gradle
@@ -0,0 +1,48 @@
/*
* Copyright (C) 2017. Uber Technologies
*
* 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
*
* http://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.
*/
plugins {
id "java"
// For code coverage:
id 'jacoco'
id 'com.github.kt3k.coveralls'
}

sourceCompatibility = "1.8"
targetCompatibility = "1.8"

dependencies {
testCompile deps.test.junit4
testCompile(deps.build.errorProneTestHelpers) {
exclude group: "junit", module: "junit"
}
testCompile project(":nullaway")
testCompile project(":jar-infer:test-java-lib-jarinfer")

}


test {
maxHeapSize = "1024m"
jvmArgs "-Xbootclasspath/p:${configurations.errorproneJavac.asPath}"
}

// From https://github.com/kt3k/coveralls-gradle-plugin
jacocoTestReport {
reports {
xml.enabled = true // coveralls plugin depends on xml format report
html.enabled = true
}
}
@@ -0,0 +1,70 @@
package com.uber.nullaway.jarinfer;

import com.google.errorprone.CompilationTestHelper;
import com.uber.nullaway.NullAway;
import java.util.Arrays;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;

public class JarInferIntegrationTest {

@Rule public final TemporaryFolder temporaryFolder = new TemporaryFolder();

private CompilationTestHelper compilationHelper;

@Before
public void setup() {
compilationHelper = CompilationTestHelper.newInstance(NullAway.class, getClass());
}

@Test
public void jarinferLoadStubsTest() {
compilationHelper
.setArgs(
Arrays.asList(
"-d",
temporaryFolder.getRoot().getAbsolutePath(),
"-XepOpt:NullAway:AnnotatedPackages=com.uber",
"-XepOpt:NullAway:JarInferEnabled=true",
"-XepOpt:NullAway:UnannotatedSubPackages=com.uber.nullaway.[a-zA-Z0-9.]+.unannotated"))
.addSourceLines(
"Test.java",
"package com.uber;",
"import javax.annotation.Nullable;",
"import com.uber.nullaway.jarinfer.toys.unannotated.Toys;",
"class Test {",
" void test1(@Nullable String s) {",
" // BUG: Diagnostic contains: passing @Nullable parameter 's'",
" Toys.test1(s, \"let's\", \"try\");",
" }",
"}")
.doTest();
}

@Test
public void jarinferNullableReturnsTest() {
compilationHelper
.setArgs(
Arrays.asList(
"-d",
temporaryFolder.getRoot().getAbsolutePath(),
"-XepOpt:NullAway:AnnotatedPackages=com.uber",
"-XepOpt:NullAway:UnannotatedSubPackages=com.uber.nullaway.[a-zA-Z0-9.]+.unannotated",
"-XepOpt:NullAway:JarInferEnabled=true",
"-XepOpt:NullAway:JarInferUseReturnAnnotations=true"))
.addSourceLines(
"Test.java",
"package com.uber;",
"import javax.annotation.Nullable;",
"import com.uber.nullaway.jarinfer.toys.unannotated.Toys;",
"class Test {",
" void test1(@Nullable String s) {",
" // BUG: Diagnostic contains: passing @Nullable parameter 'Toys.getString(false, s)'",
" Toys.test1(Toys.getString(false, s), \"let's\", \"try\");",
" }",
"}")
.doTest();
}
}
1 change: 0 additions & 1 deletion nullaway/build.gradle
Expand Up @@ -51,7 +51,6 @@ dependencies {
testCompile deps.test.cfQual
testCompile deps.test.cfCompatQual
testCompile project(":test-java-lib")
testCompile project(":jar-infer:test-java-lib-jarinfer")
testCompile deps.test.inferAnnotations
testCompile deps.apt.javaxInject
testCompile deps.test.rxjava2
Expand Down
7 changes: 7 additions & 0 deletions nullaway/src/main/java/com/uber/nullaway/AbstractConfig.java
Expand Up @@ -89,6 +89,8 @@ public abstract class AbstractConfig implements Config {
protected String autofixSuppressionComment;

/** --- JarInfer configs --- */
protected boolean jarInferEnabled;

protected boolean jarInferUseReturnAnnotations;

protected String jarInferRegexStripModelJarName;
Expand Down Expand Up @@ -229,6 +231,11 @@ static MethodClassAndName create(String enclosingClass, String methodName) {
}

/** --- JarInfer configs --- */
@Override
public boolean isJarInferEnabled() {
return jarInferEnabled;
}

@Override
public boolean isJarInferUseReturnAnnotations() {
return jarInferUseReturnAnnotations;
Expand Down
7 changes: 5 additions & 2 deletions nullaway/src/main/java/com/uber/nullaway/Config.java
Expand Up @@ -121,9 +121,12 @@ public interface Config {
*/
String getAutofixSuppressionComment();

// --- JarInfer configs ---

/** @return true if JarInfer should be enabled */
boolean isJarInferEnabled();

/**
* --- JarInfer configs ---
*
* @return true if NullAway should use the @Nullable return value annotations inferred by
* JarInfer.
*/
Expand Down
Expand Up @@ -123,6 +123,11 @@ public String getAutofixSuppressionComment() {
throw new IllegalStateException(error_msg);
}

@Override
public boolean isJarInferEnabled() {
throw new IllegalStateException(error_msg);
}

/** --- JarInfer configs --- */
@Override
public boolean isJarInferUseReturnAnnotations() {
Expand Down
Expand Up @@ -57,6 +57,8 @@ final class ErrorProneCLIFlagsConfig extends AbstractConfig {
EP_FL_NAMESPACE + ":AcknowledgeRestrictiveAnnotations";
static final String FL_SUPPRESS_COMMENT = EP_FL_NAMESPACE + ":AutoFixSuppressionComment";
/** --- JarInfer configs --- */
static final String FL_JI_ENABLED = EP_FL_NAMESPACE + ":JarInferEnabled";

static final String FL_JI_USE_RETURN = EP_FL_NAMESPACE + ":JarInferUseReturnAnnotations";

static final String FL_JI_REGEX_MODEL_PATH = EP_FL_NAMESPACE + ":JarInferRegexStripModelJar";
Expand Down Expand Up @@ -122,6 +124,7 @@ final class ErrorProneCLIFlagsConfig extends AbstractConfig {
"Invalid -XepOpt" + FL_SUPPRESS_COMMENT + " value. Comment must be single line.");
}
/** --- JarInfer configs --- */
jarInferEnabled = flags.getBoolean(FL_JI_ENABLED).orElse(false);
jarInferUseReturnAnnotations = flags.getBoolean(FL_JI_USE_RETURN).orElse(false);
// The defaults of these two options translate to: remove .aar/.jar from the file name, and also
// implicitly mean that NullAway will search for jarinfer models in the same jar which contains
Expand Down
Expand Up @@ -43,7 +43,9 @@ public static Handler buildDefault(Config config) {
// bytecode annotations
handlerListBuilder.add(new RestrictiveAnnotationHandler(config));
}
handlerListBuilder.add(new InferredJARModelsHandler(config));
if (config.isJarInferEnabled()) {
handlerListBuilder.add(new InferredJARModelsHandler(config));
}
handlerListBuilder.add(new LibraryModelsHandler());
handlerListBuilder.add(new RxNullabilityPropagator());
handlerListBuilder.add(new ContractHandler());
Expand Down
47 changes: 0 additions & 47 deletions nullaway/src/test/java/com/uber/nullaway/NullAwayTest.java
Expand Up @@ -1207,53 +1207,6 @@ public void testReadStaticInConstructor() {
.doTest();
}

@Test
public void jarinferLoadStubsTest() {
compilationHelper
.setArgs(
Arrays.asList(
"-d",
temporaryFolder.getRoot().getAbsolutePath(),
"-XepOpt:NullAway:AnnotatedPackages=com.uber",
"-XepOpt:NullAway:UnannotatedSubPackages=com.uber.nullaway.[a-zA-Z0-9.]+.unannotated"))
.addSourceLines(
"Test.java",
"package com.uber;",
"import javax.annotation.Nullable;",
"import com.uber.nullaway.jarinfer.toys.unannotated.Toys;",
"class Test {",
" void test1(@Nullable String s) {",
" // BUG: Diagnostic contains: passing @Nullable parameter 's'",
" Toys.test1(s, \"let's\", \"try\");",
" }",
"}")
.doTest();
}

@Test
public void jarinferNullableReturnsTest() {
compilationHelper
.setArgs(
Arrays.asList(
"-d",
temporaryFolder.getRoot().getAbsolutePath(),
"-XepOpt:NullAway:AnnotatedPackages=com.uber",
"-XepOpt:NullAway:UnannotatedSubPackages=com.uber.nullaway.[a-zA-Z0-9.]+.unannotated",
"-XepOpt:NullAway:JarInferUseReturnAnnotations=true"))
.addSourceLines(
"Test.java",
"package com.uber;",
"import javax.annotation.Nullable;",
"import com.uber.nullaway.jarinfer.toys.unannotated.Toys;",
"class Test {",
" void test1(@Nullable String s) {",
" // BUG: Diagnostic contains: passing @Nullable parameter 'Toys.getString(false, s)'",
" Toys.test1(Toys.getString(false, s), \"let's\", \"try\");",
" }",
"}")
.doTest();
}

@Test
public void customErrorURL() {
compilationHelper
Expand Down
1 change: 1 addition & 0 deletions settings.gradle
Expand Up @@ -23,3 +23,4 @@ include ':jar-infer:android-jarinfer-models-sdk28'
include ':jar-infer:jar-infer-lib'
include ':jar-infer:jar-infer-cli'
include ':jar-infer:test-java-lib-jarinfer'
include ':jar-infer:nullaway-integration-test'