Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file added SKIP-REQUIRE-JAVADOC
Empty file.
11 changes: 9 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ plugins {
// https://github.com/diffplug/spotless/tags ; see tags starting "gradle/"
// Only works on JDK 11+ (even including the plugin crashes Gradle on JDK 8).
id 'com.diffplug.spotless' version '8.2.1'
id 'com.github.andygoossens.modernizer' version '1.12.0'
}

// There is another `repositories { ... }` block below; if you change this one, change that one as well.
Expand Down Expand Up @@ -174,14 +175,14 @@ allprojects { currentProj ->
// * backward-incompatible changes have been made to APIs or elsewhere.
// To make a snapshot release, version should end in "-SNAPSHOT", then: ./gradlew publish
version = '3.49.5-eisop1-SNAPSHOT'
group = 'io.github.eisop'

apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'com.gradleup.shadow'
apply plugin: 'de.undercouch.download'
apply plugin: 'net.ltgt.errorprone'

group = 'io.github.eisop'
apply plugin: 'com.github.andygoossens.modernizer'

// Keep in sync with "repositories { ... }" block above.
repositories {
Expand Down Expand Up @@ -443,6 +444,12 @@ allprojects { currentProj ->
}
}

modernizer {
failOnViolations = true
includeTestClasses = true
javaVersion = 8
}

// Add the fat checker.jar to the classpath of every Javadoc task. This allows Javadoc in
// any module to reference classes in any other module.
// Also, build and use ManualTaglet as a taglet.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public void test_castPresent() {

Assert.assertTrue(nonEmptyOpt.isPresent());
@Present Optional<String> foo = OptionalUtil.castPresent(nonEmptyOpt);
Assert.assertEquals(foo.get(), "non-empty");
Assert.assertEquals("non-empty", foo.orElseThrow());

Assert.assertFalse(emptyOpt.isPresent());
Assert.assertThrows(Error.class, () -> OptionalUtil.castPresent(emptyOpt));
Expand Down
3 changes: 3 additions & 0 deletions checker/bin-devel/test-misc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,6 @@ git diff --exit-code docs/manual/contributors.tex \

# Check gradle tasks are configured properly
./gradlew tasks

# Check that modern APIs are used
./gradlew modernizer
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@
import org.checkerframework.javacutil.UserError;
import org.plumelib.reflection.Signatures;

import java.io.File;
import java.lang.annotation.Annotation;
import java.nio.file.Paths;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
Expand Down Expand Up @@ -229,7 +229,7 @@ private void loadAllExternalUnits() {

// load external directories of units
for (String directoryName : checker.getStringsOption("unitsDirs", ':')) {
if (!new File(directoryName).exists()) {
if (!Paths.get(directoryName).toFile().exists()) {
throw new UserError("Nonexistent directory in -AunitsDirs: " + directoryName);
}
loadExternalDirectory(directoryName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import org.checkerframework.checker.nullness.qual.Nullable;

import java.io.File;
import java.nio.file.Path;

/**
* Options for running analysis on files.
Expand Down Expand Up @@ -90,7 +91,7 @@ public static CFGVisualizeOptions parseArgs(String[] args) {
System.exit(1);
}
String input = args[0];
File file = new File(input);
File file = Path.of(input).toFile();
Copy link

Copilot AI Feb 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Path.of(...) is not available on Java 8. To preserve Java 8 compatibility, use Paths.get(input).toFile() here.

Copilot uses AI. Check for mistakes.
if (!file.canRead()) {
printError("Cannot read input file: " + file.getAbsolutePath());
printUsage();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ public void shutdown() {
// Open for append, in case of multiple sub-checkers.
try (Writer fstream =
Files.newBufferedWriter(
Paths.get(outDir + "/methods.txt"),
Paths.get(outDir, "methods.txt"),
StandardCharsets.UTF_8,
StandardOpenOption.CREATE,
StandardOpenOption.APPEND);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ public void run() {
// Only run if annotated files have been created.
// See ainferTest task.
if (generationTest != null
&& !new File("tests/ainfer-" + CHECKER_SHORT_NAME + "/annotated/").exists()) {
&& !Files.exists(Paths.get("tests", "ainfer-" + CHECKER_SHORT_NAME, "annotated"))) {
throw new RuntimeException(generationTest + " must be run before this test.");
}
super.run();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ public void run() {
customizeOptions(Collections.unmodifiableList(checkerOptions));
TestConfiguration config =
TestConfigurationBuilder.buildDefaultConfiguration(
new File(resolveTestDirectory(), testDir).getPath(),
resolveTestDirectory().toPath().resolve(testDir).toString(),
testFiles,
classpathExtra,
checkerNames,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public void run() {
customizeOptions(Collections.unmodifiableList(checkerOptions));
TestConfiguration config =
TestConfigurationBuilder.buildDefaultConfiguration(
new File(resolveTestDirectory(), testDir).getPath(),
resolveTestDirectory().toPath().resolve(testDir).toString(),
testFile,
checker,
customizedOptions,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.checkerframework.framework.test;

import java.io.File;
import java.nio.file.Paths;

/** Encapsulates the directory root to search within for test files to compile. */
abstract class CheckerFrameworkRootedTest {
Expand All @@ -17,9 +18,9 @@ public CheckerFrameworkRootedTest() {}
protected File resolveTestDirectory() {
TestRootDirectory annotation = getClass().getAnnotation(TestRootDirectory.class);
if (annotation != null) {
return new File(annotation.value());
return Paths.get(annotation.value()).toFile();
}
return new File("tests");
return Paths.get("tests").toFile();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ protected void doNotTypecheck(
* @return whether {@code file} contains {@code skipComment}
*/
public static boolean hasSkipComment(File file, String skipComment) {
try (Scanner in = new Scanner(file, StandardCharsets.UTF_8.name())) {
try (Scanner in = new Scanner(file, StandardCharsets.UTF_8)) {
while (in.hasNext()) {
String nextLine = in.nextLine();
if (nextLine.contains(skipComment)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.junit.runners.model.InitializationError;

import java.io.File;
import java.nio.file.Path;
import java.util.List;

/**
Expand Down Expand Up @@ -33,8 +34,8 @@ public RootedSuite(Class<?> klass, List<Runner> runners) throws InitializationEr
protected final File resolveTestDirectory() {
TestRootDirectory annotation = getTestClass().getAnnotation(TestRootDirectory.class);
if (annotation != null) {
return new File(annotation.value());
return Path.of(annotation.value()).toFile();
}
return new File("tests");
return Path.of("tests").toFile();
Comment on lines +37 to +39
Copy link

Copilot AI Feb 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Path.of(...) requires Java 11+. If this project is intended to be compatible with Java 8 (as indicated by modernizer javaVersion = 8), replace these with Paths.get(...).

Copilot uses AI. Check for mistakes.
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.plumelib.util.StringsPlume;

import java.io.File;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
Expand Down Expand Up @@ -597,10 +598,15 @@ private static <T> List<T> catListAndIterable(
* @return the output directory
*/
public static File getOutputDirFromProperty() {
return new File(
System.getProperty(
"tests.outputDir",
"tests" + File.separator + "build" + File.separator + "testclasses"));
return Paths.get(
System.getProperty(
"tests.outputDir",
"tests"
+ File.separator
+ "build"
+ File.separator
+ "testclasses"))
.toFile();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public class TestUtilities {
* @return found files
*/
public static List<File> findNestedJavaTestFiles(String... dirNames) {
return findRelativeNestedJavaFiles(new File("tests"), dirNames);
return findRelativeNestedJavaFiles(Paths.get("tests").toFile(), dirNames);
}

/**
Expand All @@ -96,7 +96,7 @@ public static List<File> findNestedJavaTestFiles(String... dirNames) {
* @return found files
*/
public static List<File> findRelativeNestedJavaFiles(String parent, String... dirNames) {
return findRelativeNestedJavaFiles(new File(parent), dirNames);
return findRelativeNestedJavaFiles(Paths.get(parent).toFile(), dirNames);
}

/**
Expand All @@ -111,7 +111,7 @@ public static List<File> findRelativeNestedJavaFiles(File parent, String... dirN

int i = 0;
for (String dirName : dirNames) {
dirs[i] = new File(parent, dirName);
dirs[i] = parent.toPath().resolve(dirName).toFile();
++i;
}

Expand Down Expand Up @@ -140,7 +140,7 @@ public static List<List<File>> findJavaFilesPerDirectory(File parent, String...
List<List<File>> filesPerDirectory = new ArrayList<>();

for (String dirName : dirNames) {
File dir = new File(parent, dirName).toPath().toAbsolutePath().normalize().toFile();
File dir = parent.toPath().resolve(dirName).toAbsolutePath().normalize().toFile();
if (dir.isDirectory()) {
filesPerDirectory.addAll(findJavaTestFilesInDirectory(dir));
} else {
Expand Down Expand Up @@ -168,8 +168,8 @@ public static List<List<File>> findJavaFilesPerDirectory(File parent, String...
throw new BugInCF("test directory does not exist: %s", dir);
}
p =
new File(parent, allSystemPath.replace("/", File.separator))
.toPath()
parent.toPath()
.resolve(allSystemPath.replace("/", File.separator))
.toAbsolutePath()
.normalize()
.toFile();
Expand Down Expand Up @@ -206,7 +206,7 @@ private static List<List<File>> findJavaTestFilesInDirectory(File dir) {
}
Arrays.sort(dirContents);
for (String fileName : dirContents) {
File file = new File(dir, fileName);
File file = dir.toPath().resolve(fileName).toFile();
if (file.isDirectory()) {
fileGroupedByDirectory.addAll(findJavaTestFilesInDirectory(file));
} else if (isJavaTestFile(file)) {
Expand All @@ -228,7 +228,7 @@ private static List<List<File>> findJavaTestFilesInDirectory(File dir) {
*/
public static List<Object[]> findFilesInParent(File parent, String... fileNames) {
return CollectionsPlume.mapList(
(String fileName) -> new Object[] {new File(parent, fileName)}, fileNames);
(String fileName) -> new Object[] {parent.toPath().resolve(fileName)}, fileNames);
Copy link

Copilot AI Feb 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This changes the element type from File to Path inside the returned Object[]. Callers (especially JUnit parameterized tests) that expect a File will now fail with a ClassCastException or method signature mismatch. Convert the resolved path back to File (e.g., .toFile()) to preserve the original API behavior.

Suggested change
(String fileName) -> new Object[] {parent.toPath().resolve(fileName)}, fileNames);
(String fileName) ->
new Object[] {parent.toPath().resolve(fileName).toFile()},
fileNames);

Copilot uses AI. Check for mistakes.
}

/**
Expand Down Expand Up @@ -385,12 +385,13 @@ public static String summarizeSourceFiles(List<File> javaFiles) {
}

public static File getTestFile(String fileRelativeToTestsDir) {
return new File("tests", fileRelativeToTestsDir);
return Paths.get("tests", fileRelativeToTestsDir).toFile();
}

public static File findComparisonFile(File testFile) {
File comparisonFile =
new File(testFile.getParent(), testFile.getName().replace(".java", ".out"));
Paths.get(testFile.getParent(), testFile.getName().replace(".java", ".out"))
.toFile();
return comparisonFile;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import java.io.LineNumberReader;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
Expand Down Expand Up @@ -208,7 +209,7 @@ private JavaDiagnosticReader(File toRead, StringToTestDiagnosticLine codec) {
private JavaDiagnosticReader(
JavaFileObject toReadFileObject, StringToTestDiagnosticLine codec) {
this.codec = codec;
this.filename = new File(toReadFileObject.getName()).getName();
this.filename = Paths.get(toReadFileObject.getName()).toFile().getName();
LineNumberReader reader = null;
try {
reader = new LineNumberReader(toReadFileObject.openReader(true));
Expand Down
Loading
Loading