Skip to content

Commit 07b86d6

Browse files
committed
chore: switch to jspecify
1 parent 5789486 commit 07b86d6

File tree

63 files changed

+141
-117
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+141
-117
lines changed

build.gradle.kts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ allprojects {
6767
testImplementation(rootProject.libs.asmCommons)
6868
}
6969

70-
compileOnlyApi(rootProject.libs.checkerQual)
71-
testCompileOnly(rootProject.libs.checkerQual)
70+
compileOnlyApi(rootProject.libs.jspecify)
71+
testCompileOnly(rootProject.libs.jspecify)
7272
compileOnly(rootProject.libs.jetbrainsAnnotations)
7373
testCompileOnly(rootProject.libs.jetbrainsAnnotations)
7474

@@ -80,7 +80,7 @@ allprojects {
8080

8181
javadocLinks {
8282
override(startsWithAnyOf("org.ow2.asm:asm"), JavadocLinksExtension.LinkOverride.Simple("https://asm.ow2.io/javadoc"))
83-
override(rootProject.libs.checkerQual, "https://checkerframework.org/api/")
83+
override(rootProject.libs.jspecify, "https://jspecify.dev/docs/api/")
8484
}
8585
}
8686
val mainForNewTargets = sourceSets.create("mainForNewTargets")

gradle/libs.versions.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ jbAnnos = "26.0.2"
99
[libraries]
1010
asm = { module = "org.ow2.asm:asm", version.ref = "asm" }
1111
asmCommons = { module = "org.ow2.asm:asm-commons", version.ref = "asm" }
12-
checkerQual = "org.checkerframework:checker-qual:3.49.4"
12+
jspecify = { module = "org.jspecify:jspecify", version = "1.0.0" }
1313
jetbrainsAnnotations = { module = "org.jetbrains:annotations", version.ref = "jbAnnos" }
1414

1515
jupiterApi = { module = "org.junit.jupiter:junit-jupiter-api", version.ref = "junit" }

reflection-rewriter/proxy-generator/src/main/java/io/papermc/reflectionrewriter/proxygenerator/ProxyGenerator.java

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,8 @@
88
import java.util.List;
99
import java.util.Objects;
1010
import java.util.Set;
11-
import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
12-
import org.checkerframework.checker.nullness.qual.NonNull;
13-
import org.checkerframework.checker.nullness.qual.Nullable;
14-
import org.checkerframework.framework.qual.DefaultQualifier;
11+
import org.jspecify.annotations.NullMarked;
12+
import org.jspecify.annotations.Nullable;
1513
import org.objectweb.asm.ClassReader;
1614
import org.objectweb.asm.ClassVisitor;
1715
import org.objectweb.asm.ClassWriter;
@@ -41,7 +39,7 @@
4139
/**
4240
* Generates holder classes for reflection proxy instances.
4341
*/
44-
@DefaultQualifier(NonNull.class)
42+
@NullMarked
4543
public final class ProxyGenerator {
4644
private ProxyGenerator() {
4745
}
@@ -164,7 +162,7 @@ private static Set<Class<?>> findParents(final Class<?> clazz) {
164162
}
165163

166164
private static void findParents(final Set<Class<?>> ret, final Class<?> clazz) {
167-
final @Nullable Class<?> superClass = clazz.getSuperclass();
165+
final Class<?> superClass = clazz.getSuperclass();
168166
if (superClass != null && superClass != Object.class) {
169167
ret.add(superClass);
170168
findParents(ret, superClass);
@@ -176,7 +174,7 @@ private static void findParents(final Set<Class<?>> ret, final Class<?> clazz) {
176174
}
177175

178176
private static ClassReader classReader(final String className) {
179-
try (final @Nullable InputStream is = ProxyGenerator.class.getClassLoader().getResourceAsStream(className.replace('.', '/') + ".class")) {
177+
try (final InputStream is = ProxyGenerator.class.getClassLoader().getResourceAsStream(className.replace('.', '/') + ".class")) {
180178
Objects.requireNonNull(is, () -> "Class '" + className + "'");
181179
return new ClassReader(is);
182180
} catch (final Exception ex) {
@@ -217,7 +215,7 @@ public int hashCode() {
217215

218216
private static final class DiscoverMethodsVisitor extends ClassVisitor {
219217
private final List<MethodInfo> methods;
220-
private @MonotonicNonNull String name;
218+
private @Nullable String name;
221219

222220
DiscoverMethodsVisitor(final int api, final @Nullable ClassVisitor visitor) {
223221
super(api, visitor);

reflection-rewriter/rewriter/src/main/java/io/papermc/reflectionrewriter/DefineClassRule.java

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,13 @@
1010
import java.lang.constant.ClassDesc;
1111
import java.lang.constant.MethodTypeDesc;
1212
import java.util.Set;
13-
import org.checkerframework.checker.nullness.qual.NonNull;
14-
import org.checkerframework.checker.nullness.qual.Nullable;
15-
import org.checkerframework.framework.qual.DefaultQualifier;
13+
import org.jspecify.annotations.Nullable;
1614

1715
import static io.papermc.asm.util.DescriptorUtils.fromOwner;
1816
import static io.papermc.asm.util.DescriptorUtils.toOwner;
1917
import static io.papermc.asm.util.OpcodeUtils.isStatic;
2018
import static io.papermc.asm.util.OpcodeUtils.staticOp;
2119

22-
@DefaultQualifier(NonNull.class)
2320
public final class DefineClassRule implements MethodRewriteRule {
2421
private static final Set<String> CLASS_LOADER_DESCS = Set.of(
2522
"([BII)Ljava/lang/Class;",
@@ -66,7 +63,7 @@ public boolean shouldProcess(final ClassProcessingContext context, final int opc
6663
descriptor = descriptor.insertParameterTypes(0, fromOwner("java/lang/invoke/MethodHandles$Lookup"));
6764
new SimpleRewrite(staticOp(isInvokeDynamic), this.proxy, name, descriptor, false, isInvokeDynamic);
6865
}
69-
final @Nullable String superName = context.processingClassSuperClassName();
66+
final String superName = context.processingClassSuperClassName();
7067
if (superName != null) {
7168
if (CLASS_LOADER_DESCS.contains(descriptor.descriptorString())
7269
&& this.isClassLoader(context.classInfoProvider(), superName)
@@ -120,9 +117,9 @@ private static boolean is(final ClassInfoProvider classInfoProvider, final Strin
120117
if (className.equals(checkForName)) {
121118
return true;
122119
}
123-
final @Nullable ClassInfo info = classInfoProvider.info(className);
120+
final ClassInfo info = classInfoProvider.info(className);
124121
if (info != null) {
125-
final @Nullable String superName = info.superClassName();
122+
final String superName = info.superClassName();
126123
if (superName != null) {
127124
return is(classInfoProvider, superName, checkForName, assumeClassLoader);
128125
} else {

reflection-rewriter/rewriter/src/main/java/io/papermc/reflectionrewriter/EnumRule.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import java.lang.constant.ClassDesc;
99
import java.lang.invoke.ConstantBootstraps;
1010
import java.util.function.Predicate;
11-
import org.checkerframework.checker.nullness.qual.Nullable;
1211
import org.objectweb.asm.ClassVisitor;
1312
import org.objectweb.asm.MethodVisitor;
1413
import org.objectweb.asm.Opcodes;
@@ -102,7 +101,7 @@ public void visitMaxs(final int maxStack, final int maxLocals) {
102101
public void visitMethodInsn(final int opcode, final String owner, final String name, final String descriptor, final boolean isInterface) {
103102
if (this.ownerPredicate.test(owner) && name.equals("valueOf") && descriptor.equals("(Ljava/lang/String;)L" + owner + ";")) {
104103
// Rewrite SomeEnum.valueOf(String)
105-
final @Nullable ClassInfo info = this.classInfoProvider.info(owner);
104+
final ClassInfo info = this.classInfoProvider.info(owner);
106105
if (info != null && info.isEnum()) {
107106
// Increase max stack size for this method by one for the class parameter
108107
// Note that in some cases this does not actually have to be increased (which we cannot track here),
@@ -128,7 +127,7 @@ private boolean isEnum(final String owner) {
128127
if (owner.equals("java/lang/Enum")) {
129128
return true;
130129
}
131-
final @Nullable ClassInfo info = this.classInfoProvider.info(owner);
130+
final ClassInfo info = this.classInfoProvider.info(owner);
132131
return info != null && info.isEnum();
133132
}
134133
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
@NullMarked
2+
package io.papermc.reflectionrewriter;
3+
4+
import org.jspecify.annotations.NullMarked;

reflection-rewriter/runtime/src/main/java/io/papermc/reflectionrewriter/runtime/AbstractDefaultRulesReflectionProxy.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,7 @@
1111
import java.lang.reflect.Field;
1212
import java.lang.reflect.Method;
1313
import java.util.Objects;
14-
import org.checkerframework.checker.nullness.qual.NonNull;
15-
import org.checkerframework.framework.qual.DefaultQualifier;
1614

17-
@DefaultQualifier(NonNull.class)
1815
public abstract class AbstractDefaultRulesReflectionProxy implements DefaultRulesReflectionProxy {
1916
protected AbstractDefaultRulesReflectionProxy() {
2017
}
@@ -166,7 +163,7 @@ public CallSite metafactory(final MethodHandles.Lookup caller, final String inte
166163

167164
@Override
168165
public CallSite altMetafactory(final MethodHandles.Lookup caller, final String interfaceMethodName, final MethodType factoryType, final Object... args) throws LambdaConversionException {
169-
if (args.length < 3 || !(args[2] instanceof MethodType dynamicMethodType)) {
166+
if (args.length < 3 || !(args[2] instanceof final MethodType dynamicMethodType)) {
170167
throw new IllegalArgumentException("illegal or missing argument");
171168
}
172169
return LambdaMetafactory.altMetafactory(caller, this.mapMethodName(factoryType.returnType(), interfaceMethodName, dynamicMethodType.parameterArray()), factoryType, args);

reflection-rewriter/runtime/src/main/java/io/papermc/reflectionrewriter/runtime/DefaultRulesReflectionProxy.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
import java.lang.invoke.VarHandle;
99
import java.lang.reflect.Field;
1010
import java.lang.reflect.Method;
11-
import org.checkerframework.checker.nullness.qual.NonNull;
12-
import org.checkerframework.framework.qual.DefaultQualifier;
1311

1412
/**
1513
* Interface with all the methods needed for the default rules to function.
@@ -18,7 +16,6 @@
1816
* should be used to generate a class with a static field holding an instance
1917
* of your proxy, and static methods redirecting to that instance.</p>
2018
*/
21-
@DefaultQualifier(NonNull.class)
2219
@SuppressWarnings("checkstyle:MethodName") // These methods have their names copied from the method we are proxying
2320
public interface DefaultRulesReflectionProxy {
2421
// Begin standard reflection

reflection-rewriter/runtime/src/main/java/io/papermc/reflectionrewriter/runtime/DefineClassReflectionProxyImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import java.util.Map;
1111
import java.util.concurrent.ConcurrentHashMap;
1212
import java.util.function.Function;
13-
import org.checkerframework.checker.nullness.qual.Nullable;
13+
import org.jspecify.annotations.Nullable;
1414

1515
final class DefineClassReflectionProxyImpl implements DefineClassReflectionProxy {
1616
private static final MethodHandles.Lookup LOOKUP = MethodHandles.lookup();

reflection-rewriter/runtime/src/main/java/io/papermc/reflectionrewriter/runtime/EnumRuleReflectionProxy.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
package io.papermc.reflectionrewriter.runtime;
22

33
import java.lang.invoke.MethodHandles;
4-
import org.checkerframework.checker.nullness.qual.NonNull;
5-
import org.checkerframework.framework.qual.DefaultQualifier;
64

75
/**
86
* Has required methods for the non-default enum rule. Implement in addition to
97
* {@link DefaultRulesReflectionProxy} if using the enum rule.
108
*/
11-
@DefaultQualifier(NonNull.class)
129
public interface EnumRuleReflectionProxy {
1310
<E extends Enum<E>> E enumConstant(MethodHandles.Lookup lookup, String name, Class<E> type);
1411

0 commit comments

Comments
 (0)