Skip to content

Commit 83fe35a

Browse files
Switch to JSpecify for nullability annotations (#12)
* Switch to JSpecify for nullability annotations, null-mark all base API code * Include copyright settings in VCS, update copyright
1 parent 24c330b commit 83fe35a

16 files changed

Lines changed: 158 additions & 45 deletions

.idea/copyright/Geyser.xml

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/copyright/profiles_settings.xml

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

base/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ plugins {
55

66
dependencies {
77
api(libs.checker.qual)
8+
api(libs.jspecify)
89
api(libs.cumulus)
910
api(libs.events) {
1011
exclude(group = "com.google.guava", module = "guava")

base/src/main/java/org/geysermc/api/Geyser.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2019-2022 GeyserMC. http://geysermc.org
2+
* Copyright (c) 2019-2026 GeyserMC. http://geysermc.org
33
*
44
* Permission is hereby granted, free of charge, to any person obtaining a copy
55
* of this software and associated documentation files (the "Software"), to deal
@@ -25,21 +25,19 @@
2525

2626
package org.geysermc.api;
2727

28-
import org.checkerframework.checker.nullness.qual.NonNull;
28+
import org.jspecify.annotations.Nullable;
2929

3030
/**
3131
* General API class for Geyser.
3232
*/
33-
@NonNull
3433
public class Geyser {
35-
private static GeyserApiBase api;
34+
private static @Nullable GeyserApiBase api;
3635

3736
/**
3837
* Returns the base api.
3938
*
4039
* @return the base api
4140
*/
42-
@NonNull
4341
public static GeyserApiBase api() {
4442
if (api == null) {
4543
throw new RuntimeException("Api has not been registered yet!");
@@ -56,7 +54,7 @@ public static GeyserApiBase api() {
5654
* @return the api of the given type
5755
*/
5856
@SuppressWarnings("unchecked")
59-
public static <T extends GeyserApiBase> T api(@NonNull Class<T> apiClass) {
57+
public static <T extends GeyserApiBase> T api(Class<T> apiClass) {
6058
if (apiClass.isInstance(api)) {
6159
return (T) api;
6260
}
@@ -75,7 +73,7 @@ public static <T extends GeyserApiBase> T api(@NonNull Class<T> apiClass) {
7573
*
7674
* @param api the api
7775
*/
78-
public static void set(@NonNull GeyserApiBase api) {
76+
public static void set(GeyserApiBase api) {
7977
if (Geyser.api != null) {
8078
throw new RuntimeException("Cannot redefine already registered api!");
8179
}

base/src/main/java/org/geysermc/api/GeyserApiBase.java

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2019-2022 GeyserMC. http://geysermc.org
2+
* Copyright (c) 2019-2026 GeyserMC. http://geysermc.org
33
*
44
* Permission is hereby granted, free of charge, to any person obtaining a copy
55
* of this software and associated documentation files (the "Software"), to deal
@@ -26,13 +26,12 @@
2626
package org.geysermc.api;
2727

2828
import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
29-
import org.checkerframework.checker.nullness.qual.NonNull;
30-
import org.checkerframework.checker.nullness.qual.Nullable;
3129
import org.checkerframework.common.value.qual.IntRange;
3230
import org.geysermc.api.connection.Connection;
3331
import org.geysermc.api.util.ApiVersion;
3432
import org.geysermc.cumulus.form.Form;
3533
import org.geysermc.cumulus.form.util.FormBuilder;
34+
import org.jspecify.annotations.Nullable;
3635

3736
import java.util.List;
3837
import java.util.UUID;
@@ -48,25 +47,23 @@ public interface GeyserApiBase {
4847
* @param uuid the UUID of the connection
4948
* @return the connection from the given UUID, if applicable
5049
*/
51-
@Nullable
52-
Connection connectionByUuid(@NonNull UUID uuid);
50+
@Nullable Connection connectionByUuid(UUID uuid);
5351

5452
/**
5553
* Gets the connection from the given XUID, if applicable. This method only works for online connections.
5654
*
5755
* @param xuid the XUID of the session
5856
* @return the connection from the given UUID, if applicable
5957
*/
60-
@Nullable
61-
Connection connectionByXuid(@NonNull String xuid);
58+
@Nullable Connection connectionByXuid(String xuid);
6259

6360
/**
6461
* Method to determine if the given <b>online</b> player is a Bedrock player.
6562
*
6663
* @param uuid the uuid of the online player
6764
* @return true if the given online player is a Bedrock player
6865
*/
69-
boolean isBedrockPlayer(@NonNull UUID uuid);
66+
boolean isBedrockPlayer(UUID uuid);
7067

7168
/**
7269
* Sends a form to the given connection and opens it.
@@ -75,7 +72,7 @@ public interface GeyserApiBase {
7572
* @param form the form to send
7673
* @return whether the form was successfully sent
7774
*/
78-
boolean sendForm(@NonNull UUID uuid, @NonNull Form form);
75+
boolean sendForm(UUID uuid, Form form);
7976

8077
/**
8178
* Sends a form to the given connection and opens it.
@@ -84,7 +81,7 @@ public interface GeyserApiBase {
8481
* @param formBuilder the formBuilder to send
8582
* @return whether the form was successfully sent
8683
*/
87-
boolean sendForm(@NonNull UUID uuid, @NonNull FormBuilder<?, ?, ?> formBuilder);
84+
boolean sendForm(UUID uuid, FormBuilder<?, ?, ?> formBuilder);
8885

8986
/**
9087
* Transfer the given connection to a server. A Bedrock player can successfully transfer to the same server they are
@@ -95,12 +92,11 @@ public interface GeyserApiBase {
9592
* @param port the port of the server
9693
* @return true if the transfer was a success
9794
*/
98-
boolean transfer(@NonNull UUID uuid, @NonNull String address, @IntRange(from = 0, to = 65535) int port);
95+
boolean transfer(UUID uuid, String address, @IntRange(from = 0, to = 65535) int port);
9996

10097
/**
10198
* Returns all the online connections.
10299
*/
103-
@NonNull
104100
List<? extends Connection> onlineConnections();
105101

106102
/**

base/src/main/java/org/geysermc/api/connection/Connection.java

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2019-2022 GeyserMC. http://geysermc.org
2+
* Copyright (c) 2019-2026 GeyserMC. http://geysermc.org
33
*
44
* Permission is hereby granted, free of charge, to any person obtaining a copy
55
* of this software and associated documentation files (the "Software"), to deal
@@ -26,7 +26,6 @@
2626
package org.geysermc.api.connection;
2727

2828
import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
29-
import org.checkerframework.checker.nullness.qual.NonNull;
3029
import org.checkerframework.common.value.qual.IntRange;
3130
import org.geysermc.api.util.BedrockPlatform;
3231
import org.geysermc.api.util.InputMode;
@@ -43,7 +42,7 @@ public interface Connection {
4342
/**
4443
* Returns the bedrock name of the connection.
4544
*/
46-
@NonNull String bedrockUsername();
45+
String bedrockUsername();
4746

4847
/**
4948
* Returns the java name of the connection.
@@ -60,32 +59,32 @@ public interface Connection {
6059
/**
6160
* Returns the XUID of the connection.
6261
*/
63-
@NonNull String xuid();
62+
String xuid();
6463

6564
/**
6665
* Returns the version of the Bedrock client.
6766
*/
68-
@NonNull String version();
67+
String version();
6968

7069
/**
7170
* Returns the platform that the connection is playing on.
7271
*/
73-
@NonNull BedrockPlatform platform();
72+
BedrockPlatform platform();
7473

7574
/**
7675
* Returns the language code of the connection.
7776
*/
78-
@NonNull String languageCode();
77+
String languageCode();
7978

8079
/**
8180
* Returns the User Interface Profile of the connection.
8281
*/
83-
@NonNull UiProfile uiProfile();
82+
UiProfile uiProfile();
8483

8584
/**
8685
* Returns the Input Mode of the Bedrock client.
8786
*/
88-
@NonNull InputMode inputMode();
87+
InputMode inputMode();
8988

9089
/**
9190
* Returns whether the connection is linked.
@@ -99,15 +98,15 @@ public interface Connection {
9998
* @param form the form to send
10099
* @return whether the form was successfully sent
101100
*/
102-
boolean sendForm(@NonNull Form form);
101+
boolean sendForm(Form form);
103102

104103
/**
105104
* Sends a form to the connection and opens it.
106105
*
107106
* @param formBuilder the formBuilder to send
108107
* @return whether the form was successfully sent
109108
*/
110-
boolean sendForm(@NonNull FormBuilder<?, ?, ?> formBuilder);
109+
boolean sendForm(FormBuilder<?, ?, ?> formBuilder);
111110

112111
/**
113112
* Transfer the connection to a server. A Bedrock player can successfully transfer to the same server they are
@@ -117,5 +116,5 @@ public interface Connection {
117116
* @param port the port of the server
118117
* @return true if the transfer was a success
119118
*/
120-
boolean transfer(@NonNull String address, @IntRange(from = 0, to = 65535) int port);
119+
boolean transfer(String address, @IntRange(from = 0, to = 65535) int port);
121120
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
* Copyright (c) 2026 GeyserMC. http://geysermc.org
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a copy
5+
* of this software and associated documentation files (the "Software"), to deal
6+
* in the Software without restriction, including without limitation the rights
7+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
* copies of the Software, and to permit persons to whom the Software is
9+
* furnished to do so, subject to the following conditions:
10+
*
11+
* The above copyright notice and this permission notice shall be included in
12+
* all copies or substantial portions of the Software.
13+
*
14+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20+
* THE SOFTWARE.
21+
*
22+
* @author GeyserMC
23+
* @link https://github.com/GeyserMC/Geyser
24+
*/
25+
26+
@NullMarked
27+
package org.geysermc.api.connection;
28+
29+
import org.jspecify.annotations.NullMarked;
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
* Copyright (c) 2026 GeyserMC. http://geysermc.org
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a copy
5+
* of this software and associated documentation files (the "Software"), to deal
6+
* in the Software without restriction, including without limitation the rights
7+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
* copies of the Software, and to permit persons to whom the Software is
9+
* furnished to do so, subject to the following conditions:
10+
*
11+
* The above copyright notice and this permission notice shall be included in
12+
* all copies or substantial portions of the Software.
13+
*
14+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20+
* THE SOFTWARE.
21+
*
22+
* @author GeyserMC
23+
* @link https://github.com/GeyserMC/Geyser
24+
*/
25+
26+
@NullMarked
27+
package org.geysermc.api;
28+
29+
import org.jspecify.annotations.NullMarked;

base/src/main/java/org/geysermc/api/util/ApiVersion.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,28 @@
1+
/*
2+
* Copyright (c) 2026 GeyserMC. http://geysermc.org
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a copy
5+
* of this software and associated documentation files (the "Software"), to deal
6+
* in the Software without restriction, including without limitation the rights
7+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
* copies of the Software, and to permit persons to whom the Software is
9+
* furnished to do so, subject to the following conditions:
10+
*
11+
* The above copyright notice and this permission notice shall be included in
12+
* all copies or substantial portions of the Software.
13+
*
14+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20+
* THE SOFTWARE.
21+
*
22+
* @author GeyserMC
23+
* @link https://github.com/GeyserMC/Geyser
24+
*/
25+
126
package org.geysermc.api.util;
227

328
/**

base/src/main/java/org/geysermc/api/util/BedrockPlatform.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2019-2022 GeyserMC. http://geysermc.org
2+
* Copyright (c) 2019-2026 GeyserMC. http://geysermc.org
33
*
44
* Permission is hereby granted, free of charge, to any person obtaining a copy
55
* of this software and associated documentation files (the "Software"), to deal
@@ -25,8 +25,6 @@
2525

2626
package org.geysermc.api.util;
2727

28-
import org.checkerframework.checker.nullness.qual.NonNull;
29-
3028
public enum BedrockPlatform {
3129
UNKNOWN("Unknown"),
3230
GOOGLE("Android"),
@@ -62,7 +60,6 @@ public enum BedrockPlatform {
6260
* @param id the BedrockPlatform identifier
6361
* @return The BedrockPlatform or {@link #UNKNOWN} if the platform wasn't found
6462
*/
65-
@NonNull
6663
public static BedrockPlatform fromId(int id) {
6764
return id < VALUES.length ? VALUES[id] : VALUES[0];
6865
}

0 commit comments

Comments
 (0)