Skip to content

Commit

Permalink
Test that demonstrates the unsoundness that can occur if Lombok and t…
Browse files Browse the repository at this point in the history
…he Checker Framework are run together
  • Loading branch information
kelloggm authored Aug 19, 2021
1 parent 439a112 commit bf79d96
Show file tree
Hide file tree
Showing 4 changed files with 160 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package org.checkerframework.checker.test.junit;

import com.google.common.collect.ImmutableList;
import java.io.File;
import java.util.Collections;
import java.util.List;
import org.checkerframework.framework.test.CheckerFrameworkPerDirectoryTest;
import org.checkerframework.framework.test.TestConfiguration;
import org.checkerframework.framework.test.TestConfigurationBuilder;
import org.checkerframework.framework.test.TestUtilities;
import org.checkerframework.framework.test.TypecheckExecutor;
import org.checkerframework.framework.test.TypecheckResult;
import org.junit.runners.Parameterized.Parameters;

/**
* This test suite exists to demonstrate and keep a record of the unsoundness that occurs when
* Lombok and the Checker Framework are run in the same invocation of javac.
*/
public class CalledMethodsNoDelombokTest extends CheckerFrameworkPerDirectoryTest {

private static final ImmutableList<String> ANNOTATION_PROCS =
ImmutableList.of(
"lombok.launch.AnnotationProcessorHider$AnnotationProcessor",
"lombok.launch.AnnotationProcessorHider$ClaimingProcessor",
org.checkerframework.checker.calledmethods.CalledMethodsChecker.class.getName());

public CalledMethodsNoDelombokTest(List<File> testFiles) {
super(
testFiles,
org.checkerframework.checker.calledmethods.CalledMethodsChecker.class,
"lombok",
"-Anomsgtext",
"-nowarn");
}

@Parameters
public static String[] getTestDirs() {
return new String[] {"calledmethods-nodelombok"};
}

/**
* copy-pasted code from {@link CheckerFrameworkPerDirectoryTest#run()}, except that we change the
* annotation processors to {@link #ANNOTATION_PROCS}
*/
@Override
public void run() {
boolean shouldEmitDebugInfo = TestUtilities.getShouldEmitDebugInfo();
List<String> customizedOptions = customizeOptions(Collections.unmodifiableList(checkerOptions));
TestConfiguration config =
TestConfigurationBuilder.buildDefaultConfiguration(
testDir,
testFiles,
classpathExtra,
ANNOTATION_PROCS,
customizedOptions,
shouldEmitDebugInfo);
TypecheckResult testResult = new TypecheckExecutor().runTest(config);
TypecheckResult adjustedTestResult = adjustTypecheckResult(testResult);
TestUtilities.assertTestDidNotFail(adjustedTestResult);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package org.checkerframework.checker.test.junit;

import com.google.common.collect.ImmutableList;
import java.io.File;
import java.util.Collections;
import java.util.List;
import org.checkerframework.framework.test.CheckerFrameworkPerDirectoryTest;
import org.checkerframework.framework.test.TestConfiguration;
import org.checkerframework.framework.test.TestConfigurationBuilder;
import org.checkerframework.framework.test.TestUtilities;
import org.checkerframework.framework.test.TypecheckExecutor;
import org.checkerframework.framework.test.TypecheckResult;
import org.junit.runners.Parameterized.Parameters;

/**
* This test suite exists to demonstrate and keep a record of the unsoundness that occurs when
* Lombok and the Checker Framework are run in the same invocation of javac.
*/
public class NullnessNoDelombokTest extends CheckerFrameworkPerDirectoryTest {

private static final ImmutableList<String> ANNOTATION_PROCS =
ImmutableList.of(
"lombok.launch.AnnotationProcessorHider$AnnotationProcessor",
"lombok.launch.AnnotationProcessorHider$ClaimingProcessor",
org.checkerframework.checker.nullness.NullnessChecker.class.getName());

public NullnessNoDelombokTest(List<File> testFiles) {
super(
testFiles,
org.checkerframework.checker.nullness.NullnessChecker.class,
"nullness-nodelombok",
"-Anomsgtext",
"-nowarn");
}

@Parameters
public static String[] getTestDirs() {
return new String[] {"nullness-nodelombok"};
}

/**
* copy-pasted code from {@link CheckerFrameworkPerDirectoryTest#run()}, except that we change the
* annotation processors to {@link #ANNOTATION_PROCS}
*/
@Override
public void run() {
boolean shouldEmitDebugInfo = TestUtilities.getShouldEmitDebugInfo();
List<String> customizedOptions = customizeOptions(Collections.unmodifiableList(checkerOptions));
TestConfiguration config =
TestConfigurationBuilder.buildDefaultConfiguration(
testDir,
testFiles,
classpathExtra,
ANNOTATION_PROCS,
customizedOptions,
shouldEmitDebugInfo);
TypecheckResult testResult = new TypecheckExecutor().runTest(config);
TypecheckResult adjustedTestResult = adjustTypecheckResult(testResult);
TestUtilities.assertTestDidNotFail(adjustedTestResult);
}
}
21 changes: 21 additions & 0 deletions checker/tests/calledmethods-nodelombok/UnsoundnessTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// An example of an unsoundness that occurs when running the Called Methods Checker
// on Lombok'd code without running delombok first.

@lombok.Builder
class UnsoundnessTest {
@lombok.NonNull Object foo;
@lombok.NonNull Object bar;

static void test() {
// An error should be issued here, but the code has not been delombok'd.
// If the CF and Lombok are ever able to work in the same invocation of javac
// (i.e. without delomboking first), then this error should be changed back to an
// expected error by re-adding the leading "::".
// error: (finalizer.invocation)
builder().build();
}

static void test2() {
builder().foo(null).bar(null).build();
}
}
17 changes: 17 additions & 0 deletions checker/tests/nullness-nodelombok/UnsoundnessTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// An example of an unsoundness that occurs when running the Nullness Checker
// on Lombok'd code without running delombok first.

@lombok.Builder
class UnsoundnessTest {
@lombok.NonNull Object foo;
@lombok.NonNull Object bar;

static void test() {
// An error should be issued here, but the code has not been delombok'd.
// If the CF and Lombok are ever able to work in the same invocation of javac
// (i.e. without delomboking first), then this error should be changed back to an
// expected error by re-adding the leading "::".
// error: (assignment)
builder().foo(null).build();
}
}

0 comments on commit bf79d96

Please sign in to comment.