Skip to content

Commit 0036537

Browse files
Added experimental mode to jspecify nullability checks
These checks enable the new jdk nullability data, so nullable lib methods are properly annotated now
1 parent ec5acfd commit 0036537

6 files changed

Lines changed: 23 additions & 6 deletions

File tree

‎build.gradle.kts‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,20 @@ val jlink = tasks.register<JlinkTask>(JlinkTask.DEFAULT_TASK_NAME) {
6262
javaCompiler = javaToolchains.compilerFor(java.toolchain)
6363
}
6464

65+
nullability {
66+
jspecify {
67+
experimental = true
68+
}
69+
}
70+
6571
val CompileOptions.nullability: NullabilityOptions
66-
get() = (this as ExtensionAware).extensions["nullability"] as NullabilityOptions
72+
get() = (this as ExtensionAware).extensions.getByName("nullability") as NullabilityOptions
6773

6874
tasks.named<JavaCompile>(JavaPlugin.COMPILE_TEST_JAVA_TASK_NAME) {
6975
options.nullability.checking = "tests"
76+
options.nullability.jspecify {
77+
experimental = true
78+
}
7079
}
7180

7281
tasks.test {

‎src/main/java/com/github/stickerifier/stickerify/bot/Stickerify.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
public record Stickerify(TelegramBot bot, Executor executor) implements UpdatesListener, ExceptionHandler, AutoCloseable {
5858

5959
private static final StructuredLogger LOGGER = new StructuredLogger(Stickerify.class);
60-
private static final String BOT_TOKEN = System.getenv("STICKERIFY_TOKEN");
60+
private static final @Nullable String BOT_TOKEN = System.getenv("STICKERIFY_TOKEN");
6161
private static final ThreadFactory VIRTUAL_THREAD_FACTORY = Thread.ofVirtual().name("Virtual-", 0).factory();
6262
private static final InputRichMessage PROCESSING_MESSAGE = new InputRichMessage().html(PROCESSING.getText());
6363

‎src/main/java/com/github/stickerifier/stickerify/process/OsConstants.java‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
package com.github.stickerifier.stickerify.process;
22

33
public final class OsConstants {
4-
private static final boolean IS_WINDOWS = System.getProperty("os.name").toLowerCase().contains("windows");
4+
private static final String OS = System.getenv().getOrDefault("os.name", "");
5+
private static final boolean IS_WINDOWS = OS.toLowerCase().contains("windows");
56

67
public static final String NULL_FILE = IS_WINDOWS ? "NUL" : "/dev/null";
78

‎src/test/java/com/github/stickerifier/stickerify/ResourceHelper.java‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@
1010
public final class ResourceHelper {
1111

1212
public static File loadResource(String filename) {
13-
var resource = ResourceHelper.class.getClassLoader().getResource(filename);
13+
var cl = ResourceHelper.class.getClassLoader();
14+
assertNotNull(cl, "Classloader not found");
15+
16+
var resource = cl.getResource(filename);
1417
assertNotNull(resource, "Test resource [%s] not found.".formatted(filename));
1518

1619
return new File(resource.getFile());

‎src/test/java/com/github/stickerifier/stickerify/junit/TempFilesCleanupExtension.java‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ public void afterAll(ExtensionContext context) throws IOException {
2020

2121
private void deleteTempFiles() throws IOException {
2222
var tempFolder = System.getProperty("java.io.tmpdir");
23+
if (tempFolder == null) return;
2324

2425
try (var files = Files.list(Path.of(tempFolder))) {
2526
for (var file : files.toList()) {
@@ -31,7 +32,9 @@ private void deleteTempFiles() throws IOException {
3132
}
3233

3334
private boolean isStickerifyFile(Path path) {
34-
var fileName = path.getFileName().toString();
35+
var file = path.getFileName();
36+
if (file == null) return false;
37+
var fileName = file.toString();
3538

3639
return Files.isRegularFile(path) && (fileName.startsWith("Stickerify-") || fileName.startsWith("OriginalFile-"));
3740
}

‎src/test/java/com/github/stickerifier/stickerify/media/MediaHelperTest.java‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import static com.github.stickerifier.stickerify.media.MediaConstraints.MAX_IMAGE_FILE_SIZE;
66
import static com.github.stickerifier.stickerify.media.MediaConstraints.MAX_VIDEO_FILE_SIZE;
77
import static com.github.stickerifier.stickerify.media.MediaConstraints.VP9_CODEC;
8+
import static java.util.Objects.requireNonNullElse;
89
import static java.util.concurrent.Executors.newVirtualThreadPerTaskExecutor;
910
import static org.hamcrest.MatcherAssert.assertThat;
1011
import static org.hamcrest.Matchers.equalTo;
@@ -352,7 +353,7 @@ private static void executeConcurrentConversionsOf(File inputFile) {
352353
MediaHelper.convert(inputFile);
353354
} catch (Throwable e) {
354355
failedConversions.incrementAndGet();
355-
failureReasons.add(e.getMessage());
356+
failureReasons.add(requireNonNullElse(e.getMessage(), e.getClass().getSimpleName()));
356357
}
357358
}));
358359
}

0 commit comments

Comments
 (0)