Skip to content

Commit a6e1367

Browse files
committed
Setup errorprone and resolve issues
1 parent ac8f866 commit a6e1367

File tree

28 files changed

+68
-53
lines changed

28 files changed

+68
-53
lines changed

build-logic/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ dependencies {
1515
implementation(libs.levelHeadered)
1616
implementation(libs.shadow)
1717
implementation(libs.jfrog.buildinfo)
18+
implementation(libs.errorprone.gradle.plugin)
1819
implementation(libs.gson)
1920

2021
constraints {

build-logic/src/main/kotlin/buildlogic.common-java.gradle.kts

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import buildlogic.stringyLibs
22
import buildlogic.getLibrary
3+
import net.ltgt.gradle.errorprone.errorprone
34

45
plugins {
56
id("eclipse")
67
id("idea")
78
id("checkstyle")
9+
id("net.ltgt.errorprone")
810
id("buildlogic.common")
911
}
1012

@@ -13,7 +15,7 @@ tasks
1315
.matching { it.name == "compileJava" || it.name == "compileTestJava" }
1416
.configureEach {
1517
val disabledLint = listOf(
16-
"processing", "path", "fallthrough", "serial", "overloads", "this-escape"
18+
"processing", "path", "fallthrough", "serial", "overloads", "this-escape",
1719
)
1820
options.release.set(21)
1921
options.compilerArgs.addAll(listOf("-Xlint:all") + disabledLint.map { "-Xlint:-$it" })
@@ -23,11 +25,24 @@ tasks
2325
if (project.name.contains("-core")) {
2426
options.compilerArgs.add("-Werror")
2527
}
28+
options.errorprone {
29+
// We use -Werror, so we don't need errorprone to fail the build separately
30+
allErrorsAsWarnings = true
31+
// Obviously we don't need to fix generated code
32+
disableWarningsInGeneratedCode = true
33+
// We use reference equality intentionally in several places
34+
// Perhaps we should consider testing the performance impact of using .equals() instead?
35+
// Especially for the types that are only compared by reference equality, we could consider
36+
// removing their .equals() implementations to avoid confusion.
37+
disable("ReferenceEquality")
38+
// We're on JDK 21, so System.console() can still be null
39+
disable("SystemConsoleNull")
40+
}
2641
}
2742

2843
configure<CheckstyleExtension> {
2944
configFile = rootProject.file("config/checkstyle/checkstyle.xml")
30-
toolVersion = "10.16.0"
45+
toolVersion = "12.3.1"
3146
}
3247

3348
tasks.withType<Test>().configureEach {
@@ -38,6 +53,8 @@ tasks.withType<Test>().configureEach {
3853

3954
dependencies {
4055
"compileOnly"(stringyLibs.getLibrary("jspecify"))
56+
"compileOnly"(stringyLibs.getLibrary("errorprone-annotations"))
57+
"errorprone"(stringyLibs.getLibrary("errorprone-core"))
4158
"testImplementation"(platform(stringyLibs.getLibrary("junit-bom")))
4259
"testImplementation"(stringyLibs.getLibrary("junit-jupiter-api"))
4360
"testImplementation"(stringyLibs.getLibrary("junit-jupiter-params"))

config/checkstyle/checkstyle.xml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,9 @@ Checks based on Google Checks, modified for EngineHub.
201201
<property name="format" value="(?!Character)\.to(Lower|Upper)Case\(\)"/>
202202
<property name="illegalPattern" value="true"/>
203203
</module>
204+
<module name="PatternVariableAssignment"/>
205+
<module name="UnnecessaryNullCheckWithInstanceOf"/>
206+
<module name="WhenShouldBeUsed"/>
204207
</module>
205208
<!-- Validate that command annotations are formatted correctly -->
206209
<module name="RegexpMultiline">
@@ -249,4 +252,4 @@ Checks based on Google Checks, modified for EngineHub.
249252
<!-- Enforce package-info.java -->
250253
<module name="JavadocPackage"/>
251254

252-
</module>
255+
</module>

craftbook-bukkit/src/main/java/org/enginehub/craftbook/bukkit/mechanics/BukkitReadableBookshelf.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
import org.enginehub.craftbook.util.ProtectionUtil;
3636

3737
/**
38-
* This mechanism allow players to read bookshelves and get a random line from a file as as "book."
38+
* This mechanism allow players to read bookshelves and get a random line from a file as "book".
3939
*/
4040
public class BukkitReadableBookshelf extends ReadableBookshelf implements Listener {
4141
public BukkitReadableBookshelf(MechanicType<? extends CraftBookMechanic> mechanicType) {

craftbook-bukkit/src/main/java/org/enginehub/craftbook/mechanics/minecart/blocks/CartMechanismBlocks.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,10 @@
3434
import org.jspecify.annotations.Nullable;
3535

3636
/**
37-
* <p>
3837
* Stores the tuple of three blocks over which any typical CartMechanism is implemented,
3938
* and also performs detection of two of the blocks if only one
4039
* is given.
41-
* </p>
40+
*
4241
* <p>
4342
* Sign text and base block type are not validated by any constructors; this must be performed
4443
* explicitly by calling
@@ -47,7 +46,7 @@
4746
* fine,
4847
* since if you have two signs in an area where
4948
* they could concievably contend for control of the mechanism, you would be doing something that
50-
* ought be physically
49+
* ought to be physically
5150
* impossible anyway (though yes,
5251
* it is possible if editing the world directly without physics).
5352
* </p>
@@ -155,13 +154,12 @@ public ChangedSign getChangedSign(Side side) {
155154
}
156155

157156
/**
158-
* <p>
159157
* Detecting factory, based on the position of the rails. The base must be one block below and
160158
* the sign if it
161159
* exists must be two or three blocks
162160
* below. Signs are guaranteed to be signs (unless they're null) and rails are guaranteed to be
163161
* rails.
164-
* </p>
162+
*
165163
* <p>
166164
* This is the most important constructor, since it is the one invoked when processing cart move
167165
* events.

craftbook-bukkit/src/main/java/org/enginehub/craftbook/util/SignUtil.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,8 @@
2727
import org.jspecify.annotations.Nullable;
2828

2929
/**
30-
* <p>
3130
* Convenience methods for dealing with some sign block data.
32-
* </p>
31+
*
3332
* <p>
3433
* If you intend to care about the eight further directions (as opposed to the four cardinal
3534
* directions and the four

craftbook-core/src/main/java/org/enginehub/craftbook/AbstractCraftBookMechanic.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ public AbstractCraftBookMechanic(MechanicType<? extends CraftBookMechanic> mecha
3232
this.mechanicType = mechanicType;
3333
}
3434

35+
@Override
3536
public MechanicType<? extends CraftBookMechanic> getMechanicType() {
3637
return this.mechanicType;
3738
}

craftbook-core/src/main/java/org/enginehub/craftbook/CraftBook.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public void setup() {
7878
try {
7979
Files.createDirectories(cacheDir);
8080
} catch (IOException e) {
81-
e.printStackTrace();
81+
LOGGER.warn("Failed to create cache directory, profile cache may not work correctly.", e);
8282
}
8383
}
8484

craftbook-core/src/main/java/org/enginehub/craftbook/PlatformCommandManager.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@
5252

5353
import java.util.Collections;
5454
import java.util.List;
55-
import java.util.stream.Collectors;
5655
import java.util.stream.Stream;
5756

5857
public class PlatformCommandManager {
@@ -117,8 +116,8 @@ private MemoizingValueAccess initializeInjectedValues(Arguments arguments, Actor
117116
InjectedValueStore store = MapBackedValueStore.create();
118117

119118
store.injectValue(Key.of(Actor.class), ValueProvider.constant(actor));
120-
if (actor instanceof CraftBookPlayer) {
121-
store.injectValue(Key.of(CraftBookPlayer.class), ValueProvider.constant((CraftBookPlayer) actor));
119+
if (actor instanceof CraftBookPlayer player) {
120+
store.injectValue(Key.of(CraftBookPlayer.class), ValueProvider.constant(player));
122121
} else {
123122
store.injectValue(Key.of(CraftBookPlayer.class), context -> {
124123
throw new CommandException(
@@ -202,7 +201,7 @@ public List<Substring> handleCommandSuggestion(Actor actor, String arguments) {
202201
List<Substring> split = parseArgs(arguments).toList();
203202
List<String> argStrings = split.stream()
204203
.map(Substring::getSubstring)
205-
.collect(Collectors.toList());
204+
.toList();
206205
MemoizingValueAccess access = initializeInjectedValues(() -> arguments, actor);
207206
ImmutableSet<Suggestion> suggestions;
208207
try {
@@ -227,8 +226,9 @@ public List<Substring> handleCommandSuggestion(Actor actor, String arguments) {
227226
original.getStart() + 1,
228227
original.getEnd() + 1
229228
);
230-
}).collect(Collectors.toList());
229+
}).toList();
231230
} catch (ConditionFailedException ignored) {
231+
// Ignore condition failures.
232232
}
233233

234234
return Collections.emptyList();

craftbook-core/src/main/java/org/enginehub/craftbook/command/CraftBookExceptionConverter.java

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import com.sk89q.worldedit.internal.command.exception.ExceptionConverterHelper;
2121
import com.sk89q.worldedit.internal.command.exception.ExceptionMatch;
2222
import com.sk89q.worldedit.util.formatting.text.Component;
23-
import com.sk89q.worldedit.util.formatting.text.TextComponent;
2423
import org.enginehub.craftbook.CraftBook;
2524
import org.enginehub.craftbook.exception.CraftBookException;
2625
import org.enginehub.piston.exception.CommandException;
@@ -29,15 +28,8 @@
2928

3029
public class CraftBookExceptionConverter extends ExceptionConverterHelper {
3130

32-
private final CraftBook craftBook;
33-
3431
public CraftBookExceptionConverter(CraftBook craftBook) {
3532
checkNotNull(craftBook);
36-
this.craftBook = craftBook;
37-
}
38-
39-
private CommandException newCommandException(String message, Throwable cause) {
40-
return newCommandException(TextComponent.of(String.valueOf(message)), cause);
4133
}
4234

4335
private CommandException newCommandException(Component message, Throwable cause) {

0 commit comments

Comments
 (0)