Skip to content

Commit e717210

Browse files
authored
Annotate some of the remaining java.lang classes. (#123)
This covers my list from #112 (comment)
1 parent f070e3c commit e717210

File tree

6 files changed

+42
-21
lines changed

6 files changed

+42
-21
lines changed

src/java.base/share/classes/java/lang/AutoCloseable.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525

2626
package java.lang;
2727

28+
import org.jspecify.annotations.NullMarked;
29+
2830
/**
2931
* An object that may hold resources (such as file or socket handles)
3032
* until it is closed. The {@link #close()} method of an {@code AutoCloseable}
@@ -48,6 +50,7 @@
4850
* @author Josh Bloch
4951
* @since 1.7
5052
*/
53+
@NullMarked
5154
public interface AutoCloseable {
5255
/**
5356
* Closes this resource, relinquishing any underlying resources.

src/java.base/share/classes/java/lang/IllegalCallerException.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,16 @@
2525

2626
package java.lang;
2727

28+
import org.jspecify.annotations.NullMarked;
29+
import org.jspecify.annotations.Nullable;
30+
2831
/**
2932
* Thrown to indicate that a method has been called by an inappropriate caller.
3033
*
3134
* @since 9
3235
* @see StackWalker#getCallerClass
3336
*/
37+
@NullMarked
3438
public class IllegalCallerException extends RuntimeException {
3539
/**
3640
* Constructs an IllegalCallerException with no detail message.
@@ -45,7 +49,7 @@ public IllegalCallerException() {
4549
*
4650
* @param s the String that contains a detailed message (can be null)
4751
*/
48-
public IllegalCallerException(String s) {
52+
public IllegalCallerException(@Nullable String s) {
4953
super(s);
5054
}
5155

@@ -56,7 +60,7 @@ public IllegalCallerException(String s) {
5660
* @param message the detail message (can be null)
5761
* @param cause the cause (can be null)
5862
*/
59-
public IllegalCallerException(String message, Throwable cause) {
63+
public IllegalCallerException(@Nullable String message, @Nullable Throwable cause) {
6064
super(message, cause);
6165
}
6266

@@ -67,7 +71,7 @@ public IllegalCallerException(String message, Throwable cause) {
6771
*
6872
* @param cause the cause (can be null)
6973
*/
70-
public IllegalCallerException(Throwable cause) {
74+
public IllegalCallerException(@Nullable Throwable cause) {
7175
super(cause);
7276
}
7377

src/java.base/share/classes/java/lang/Module.java

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@
7171
import jdk.internal.reflect.Reflection;
7272
import jdk.internal.vm.annotation.Stable;
7373

74+
import org.jspecify.annotations.NullMarked;
75+
import org.jspecify.annotations.Nullable;
76+
7477
/**
7578
* Represents a run-time module, either {@link #isNamed() named} or unnamed.
7679
*
@@ -97,7 +100,7 @@
97100
* @see Class#getModule()
98101
* @jls 7.7 Module Declarations
99102
*/
100-
103+
@NullMarked
101104
public final class Module implements AnnotatedElement {
102105

103106
// the layer that contains this module, can be null
@@ -186,7 +189,7 @@ public boolean isNamed() {
186189
*
187190
* @return The module name
188191
*/
189-
public String getName() {
192+
public @Nullable String getName() {
190193
return name;
191194
}
192195

@@ -195,7 +198,7 @@ public String getName() {
195198
*
196199
* @return The class loader for this module
197200
*/
198-
public ClassLoader getClassLoader() {
201+
public @Nullable ClassLoader getClassLoader() {
199202
return loader;
200203
}
201204

@@ -205,7 +208,7 @@ public ClassLoader getClassLoader() {
205208
*
206209
* @return The module descriptor for this module
207210
*/
208-
public ModuleDescriptor getDescriptor() {
211+
public @Nullable ModuleDescriptor getDescriptor() {
209212
return descriptor;
210213
}
211214

@@ -224,7 +227,7 @@ public ModuleDescriptor getDescriptor() {
224227
*
225228
* @see java.lang.reflect.Proxy
226229
*/
227-
public ModuleLayer getLayer() {
230+
public @Nullable ModuleLayer getLayer() {
228231
if (isNamed()) {
229232
ModuleLayer layer = this.layer;
230233
if (layer != null)
@@ -1521,7 +1524,7 @@ private static Module findModule(String target,
15211524
* declaration annotation.
15221525
*/
15231526
@Override
1524-
public <T extends Annotation> T getAnnotation(Class<T> annotationClass) {
1527+
public <T extends Annotation> @Nullable T getAnnotation(Class<T> annotationClass) {
15251528
return moduleInfoClass().getDeclaredAnnotation(annotationClass);
15261529
}
15271530

@@ -1689,7 +1692,7 @@ protected Class<?> loadClass(String cn, boolean resolve)
16891692
* @see Class#getResourceAsStream(String)
16901693
*/
16911694
@CallerSensitive
1692-
public InputStream getResourceAsStream(String name) throws IOException {
1695+
public @Nullable InputStream getResourceAsStream(String name) throws IOException {
16931696
if (name.startsWith("/")) {
16941697
name = name.substring(1);
16951698
}

src/java.base/share/classes/java/lang/ModuleLayer.java

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@
5454
import jdk.internal.reflect.Reflection;
5555
import jdk.internal.vm.annotation.Stable;
5656

57+
import org.jspecify.annotations.NullMarked;
58+
import org.jspecify.annotations.Nullable;
59+
5760
/**
5861
* A layer of modules in the Java virtual machine.
5962
*
@@ -143,7 +146,7 @@
143146
* @since 9
144147
* @see Module#getLayer()
145148
*/
146-
149+
@NullMarked
147150
public final class ModuleLayer {
148151

149152
// the empty layer (may be initialized from the CDS archive)
@@ -361,7 +364,7 @@ public Controller enableNativeAccess(Module target) {
361364
* @see #findLoader
362365
*/
363366
public ModuleLayer defineModulesWithOneLoader(Configuration cf,
364-
ClassLoader parentLoader) {
367+
@Nullable ClassLoader parentLoader) {
365368
return defineModulesWithOneLoader(cf, List.of(this), parentLoader).layer();
366369
}
367370

@@ -399,7 +402,7 @@ public ModuleLayer defineModulesWithOneLoader(Configuration cf,
399402
* @see #findLoader
400403
*/
401404
public ModuleLayer defineModulesWithManyLoaders(Configuration cf,
402-
ClassLoader parentLoader) {
405+
@Nullable ClassLoader parentLoader) {
403406
return defineModulesWithManyLoaders(cf, List.of(this), parentLoader).layer();
404407
}
405408

@@ -498,7 +501,7 @@ public ModuleLayer defineModules(Configuration cf,
498501
*/
499502
public static Controller defineModulesWithOneLoader(Configuration cf,
500503
List<ModuleLayer> parentLayers,
501-
ClassLoader parentLoader)
504+
@Nullable ClassLoader parentLoader)
502505
{
503506
List<ModuleLayer> parents = List.copyOf(parentLayers);
504507
checkConfiguration(cf, parents);
@@ -562,7 +565,7 @@ public static Controller defineModulesWithOneLoader(Configuration cf,
562565
*/
563566
public static Controller defineModulesWithManyLoaders(Configuration cf,
564567
List<ModuleLayer> parentLayers,
565-
ClassLoader parentLoader)
568+
@Nullable ClassLoader parentLoader)
566569
{
567570
List<ModuleLayer> parents = List.copyOf(parentLayers);
568571
checkConfiguration(cf, parents);
@@ -862,7 +865,7 @@ boolean addEnableNativeAccess(String name) {
862865
* @throws IllegalArgumentException if a module of the given name is not
863866
* defined in this layer or any parent of this layer
864867
*/
865-
public ClassLoader findLoader(String name) {
868+
public @Nullable ClassLoader findLoader(String name) {
866869
Optional<Module> om = findModule(name);
867870

868871
// can't use map(Module::getClassLoader) as class loader can be null
@@ -906,7 +909,7 @@ public static ModuleLayer empty() {
906909
*
907910
* @return The boot layer
908911
*/
909-
public static ModuleLayer boot() {
912+
public static @Nullable ModuleLayer boot() {
910913
return System.bootLayer;
911914
}
912915

src/java.base/share/classes/java/lang/ProcessHandle.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@
3030
import java.util.concurrent.CompletableFuture;
3131
import java.util.stream.Stream;
3232

33+
import org.jspecify.annotations.NullMarked;
34+
import org.jspecify.annotations.Nullable;
35+
3336
/**
3437
* ProcessHandle identifies and provides control of native processes. Each
3538
* individual process can be monitored for liveness, list its children,
@@ -90,6 +93,7 @@
9093
* @since 9
9194
*/
9295
@jdk.internal.ValueBased
96+
@NullMarked
9397
public interface ProcessHandle extends Comparable<ProcessHandle> {
9498

9599
/**
@@ -401,7 +405,7 @@ public interface Info {
401405
* the same system process; otherwise returns {@code false}
402406
*/
403407
@Override
404-
boolean equals(Object other);
408+
boolean equals(@Nullable Object other);
405409

406410
/**
407411
* Compares this ProcessHandle with the specified ProcessHandle for order.

src/java.base/share/classes/java/lang/ReflectiveOperationException.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,17 @@
2525

2626
package java.lang;
2727

28+
import org.jspecify.annotations.NullMarked;
29+
import org.jspecify.annotations.Nullable;
30+
2831
/**
2932
* Common superclass of exceptions thrown by reflective operations in
3033
* core reflection.
3134
*
3235
* @see LinkageError
3336
* @since 1.7
3437
*/
38+
@NullMarked
3539
public class ReflectiveOperationException extends Exception {
3640
@java.io.Serial
3741
static final long serialVersionUID = 123456789L;
@@ -53,7 +57,7 @@ public ReflectiveOperationException() {
5357
* @param message the detail message. The detail message is saved for
5458
* later retrieval by the {@link #getMessage()} method.
5559
*/
56-
public ReflectiveOperationException(String message) {
60+
public ReflectiveOperationException(@Nullable String message) {
5761
super(message);
5862
}
5963

@@ -72,7 +76,7 @@ public ReflectiveOperationException(String message) {
7276
* permitted, and indicates that the cause is nonexistent or
7377
* unknown.)
7478
*/
75-
public ReflectiveOperationException(String message, Throwable cause) {
79+
public ReflectiveOperationException(@Nullable String message, @Nullable Throwable cause) {
7680
super(message, cause);
7781
}
7882

@@ -86,7 +90,7 @@ public ReflectiveOperationException(String message, Throwable cause) {
8690
* permitted, and indicates that the cause is nonexistent or
8791
* unknown.)
8892
*/
89-
public ReflectiveOperationException(Throwable cause) {
93+
public ReflectiveOperationException(@Nullable Throwable cause) {
9094
super(cause);
9195
}
9296
}

0 commit comments

Comments
 (0)