Skip to content

Commit 40d6c48

Browse files
authored
Add null safety checks at various places, bump Gradle (#63)
* Fixed NPE issues * Added even more null safety * Forgot to put -SNAPSHOT in version number lol * Was able to revert .gitignore ( left testing batch files in there by accident ) and also to revert MapIconsTransformer.java
1 parent c6081cd commit 40d6c48

9 files changed

Lines changed: 100 additions & 15 deletions

File tree

build-logic/src/main/kotlin/pack.base-conventions.gradle.kts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +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/PackConverter
24+
*
25+
*/
26+
127
import org.gradle.kotlin.dsl.`java-library`
228

329
plugins {

build-logic/src/main/kotlin/pack.publish-conventions.gradle.kts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +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/PackConverter
24+
*
25+
*/
26+
127
import java.net.URI
228

329
plugins {

converter/src/main/java/org/geysermc/pack/converter/type/texture/TextureConverter.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,13 +112,15 @@ public Collection<Texture> extract(ResourcePack pack, ExtractionContext context)
112112
String input = texture.key().value();
113113
String relativePath = input.replaceAll("\\.png$", "");
114114

115-
String rootPath = relativePath.substring(0, relativePath.indexOf('/'));
115+
int slashIndex = relativePath.indexOf('/');
116+
String rootPath = slashIndex != -1 ? relativePath.substring(0, slashIndex) : "";
116117
String bedrockRoot = DIRECTORY_LOCATIONS.getOrDefault(rootPath, rootPath);
117118

118119
List<String> mapping = mappings.map(relativePath);
119120
List<String> transformedOutputs = new ArrayList<>();
120121
for (String item : mapping) {
121-
transformedOutputs.add(bedrockRoot + item.substring(item.indexOf('/')) + ".png");
122+
int itemSlashIndex = item.indexOf('/');
123+
transformedOutputs.add(bedrockRoot + (itemSlashIndex != -1 ? item.substring(itemSlashIndex) : "/" + item) + ".png");
122124
}
123125

124126
transformed.output(transformedOutputs);
@@ -145,8 +147,9 @@ public void include(BedrockResourcePack pack, List<TransformedTexture> transform
145147
}
146148
exportedPaths.add(outputPath);
147149

148-
String root = outputPath.substring(0, outputPath.indexOf('/'));
149-
String value = outputPath.substring(outputPath.indexOf('/') + 1);
150+
int slashIndex = outputPath.indexOf('/');
151+
String root = slashIndex != -1 ? outputPath.substring(0, slashIndex) : "";
152+
String value = slashIndex != -1 ? outputPath.substring(slashIndex + 1) : outputPath;
150153

151154
outputs.add(texturePath.resolve((
152155
bedrockDirectory.formatted(root, value)

converter/src/main/java/org/geysermc/pack/converter/type/texture/transformer/TextureTransformer.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,15 @@ default int order() {
6060
}
6161

6262
default void gridTransform(@NotNull TransformContext context, boolean poll, int rows, int columns, String bedrockOutput, String... javaInputs) throws IOException {
63-
gridTransform(context, poll, rows, columns, KeyUtil.key(Key.MINECRAFT_NAMESPACE, bedrockOutput), Arrays.stream(javaInputs).map(str -> KeyUtil.key(Key.MINECRAFT_NAMESPACE, str)).toArray(Key[]::new));
63+
gridTransform(
64+
context,
65+
poll,
66+
rows,
67+
columns,
68+
KeyUtil.key(Key.MINECRAFT_NAMESPACE, bedrockOutput),
69+
Arrays.stream(javaInputs).map(
70+
str ->
71+
str == null ? null : KeyUtil.key(Key.MINECRAFT_NAMESPACE, str)).toArray(Key[]::new));
6472
}
6573

6674
// Adds images in rows and columns
@@ -85,7 +93,10 @@ default void gridTransform(@NotNull TransformContext context, boolean poll, int
8593
}
8694

8795
List<Texture> textures = Arrays.stream(javaInputs)
88-
.map(key -> poll ? context.pollOrPeekVanilla(key) : context.peekOrVanilla(key)).toList();
96+
.map(key -> {
97+
if (key == null) return null;
98+
return poll ? context.pollOrPeekVanilla(key) : context.peekOrVanilla(key);
99+
}).toList();
89100

90101
List<BufferedImage> images = new ArrayList<>(textures.size());
91102

converter/src/main/java/org/geysermc/pack/converter/type/texture/transformer/TransformContext.java

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,10 @@ public Optional<ResourcePack> vanillaPack() {
100100
* @return the texture that was removed, or null if it didn't exist
101101
*/
102102
@Nullable
103-
public Texture poll(@NotNull Key key) {
103+
public Texture poll(@Nullable Key key) {
104+
if (key == null) {
105+
return null;
106+
}
104107
Texture remove = this.byKey.remove(key);
105108
if (remove == null) {
106109
return null;
@@ -117,7 +120,10 @@ public Texture poll(@NotNull Key key) {
117120
* @return the texture with the given key, or null if it doesn't exist
118121
*/
119122
@Nullable
120-
public Texture peek(@NotNull Key key) {
123+
public Texture peek(@Nullable Key key) {
124+
if (key == null) {
125+
return null;
126+
}
121127
return this.byKey.get(key);
122128
}
123129

@@ -130,7 +136,10 @@ public Texture peek(@NotNull Key key) {
130136
* @return the texture that was removed, or the vanilla one if it didn't exist, or null
131137
*/
132138
@Nullable
133-
public Texture pollOrPeekVanilla(@NotNull Key key) {
139+
public Texture pollOrPeekVanilla(@Nullable Key key) {
140+
if (key == null) {
141+
return null;
142+
}
134143
Texture remove = this.byKey.remove(key);
135144
if (remove == null) {
136145
return vanillaPack.map(pack -> pack.texture(key)).orElse(null);
@@ -149,7 +158,10 @@ public Texture pollOrPeekVanilla(@NotNull Key key) {
149158
* @return the texture that was removed, or the vanilla one if it didn't exist, or null
150159
*/
151160
@Nullable
152-
public Texture peekOrVanilla(@NotNull Key key) {
161+
public Texture peekOrVanilla(@Nullable Key key) {
162+
if (key == null) {
163+
return null;
164+
}
153165
Texture texture = this.byKey.get(key);
154166
if (texture == null) {
155167
return vanillaPack.map(pack -> pack.texture(key)).orElse(null);
@@ -165,7 +177,10 @@ public Texture peekOrVanilla(@NotNull Key key) {
165177
* @return true if the texture is present, else false
166178
*/
167179
@SuppressWarnings("BooleanMethodIsAlwaysInverted") // It just doesn't make sense.
168-
public boolean isTexturePresent(@NotNull Key key) {
180+
public boolean isTexturePresent(@Nullable Key key) {
181+
if (key == null) {
182+
return false;
183+
}
169184
return this.byKey.containsKey(key);
170185
}
171186

converter/src/main/java/org/geysermc/pack/converter/type/texture/transformer/type/particle/GridSpritesheetParticleTransformer.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import org.geysermc.pack.converter.util.KeyUtil;
3333
import org.geysermc.pack.converter.util.StringUtils;
3434
import org.jetbrains.annotations.NotNull;
35+
import org.jetbrains.annotations.Nullable;
3536
import team.unnamed.creative.texture.Texture;
3637

3738
import java.awt.*;
@@ -78,7 +79,8 @@ public void transform(@NotNull TransformContext context) throws IOException {
7879
int k = 0;
7980
for (int i = 0; i < rows; i++) {
8081
for (int j = 0; j < columns; j++) {
81-
Key key = KeyUtil.key(Key.MINECRAFT_NAMESPACE, javaPaths[k++]);
82+
String javaPath = javaPaths[k++];
83+
Key key = javaPath == null ? null : KeyUtil.key(Key.MINECRAFT_NAMESPACE, javaPath);
8284
Texture texture = context.pollOrPeekVanilla(key);
8385
itemDatas.add(new ItemData(
8486
key,
@@ -116,7 +118,7 @@ public BufferedImage preProcessImage(BufferedImage image) {
116118
return image;
117119
}
118120

119-
private record ItemData(Key key, Texture texture, int x, int y) {}
121+
private record ItemData(@Nullable Key key, @Nullable Texture texture, int x, int y) {}
120122

121123
public static abstract class Row extends GridSpritesheetParticleTransformer {
122124
public Row(String bedrockPath, int particleWidth, int particleHeight, String javaPath, int amount) {

converter/src/main/java/org/geysermc/pack/converter/type/texture/transformer/type/particle/SpritesheetParticleTransformer.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ public void transform(@NotNull TransformContext context) throws IOException {
6060
BitSet occupiedSectors = new BitSet(this.atlasCount);
6161
Spritesheet spritesheet = new Spritesheet();
6262
for (int i = 0; i < this.atlasCount; i++) {
63+
if (javaPath == null) continue;
6364
Texture texture = context.poll(KeyUtil.key(Key.MINECRAFT_NAMESPACE, String.format(this.javaPath, i)));
6465
if (texture == null) {
6566
continue;

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
group=org.geysermc.pack
2-
version=3.4.2-SNAPSHOT
2+
version=3.4.3-SNAPSHOT
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
#Sun May 17 16:47:50 CDT 2026
12
distributionBase=GRADLE_USER_HOME
23
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip
4+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.14.4-bin.zip
45
zipStoreBase=GRADLE_USER_HOME
56
zipStorePath=wrapper/dists

0 commit comments

Comments
 (0)