Skip to content

Commit 1b178ba

Browse files
authored
Introduce @ParametersAreNonnullByDefault (#541)
* Cleaned up Nonnull/Nullable mess * Fixed some issues * Spotless after rebase * Fixes after rebase
1 parent b5b7c59 commit 1b178ba

File tree

134 files changed

+1409
-1231
lines changed

Some content is hidden

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

134 files changed

+1409
-1231
lines changed

application/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ shadowJar {
3939
}
4040

4141
dependencies {
42+
implementation 'com.google.code.findbugs:jsr305:3.0.2'
4243
implementation 'org.jetbrains:annotations:23.0.0'
4344

4445
implementation project(':database')

application/src/main/java/org/togetherjava/tjbot/Application.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,17 @@
22

33
import net.dv8tion.jda.api.JDA;
44
import net.dv8tion.jda.api.JDABuilder;
5-
import net.dv8tion.jda.api.requests.GatewayIntent;
65
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
7-
import org.jetbrains.annotations.NotNull;
6+
import net.dv8tion.jda.api.requests.GatewayIntent;
87
import org.slf4j.Logger;
98
import org.slf4j.LoggerFactory;
10-
119
import org.togetherjava.tjbot.commands.Features;
10+
import org.togetherjava.tjbot.commands.SlashCommandAdapter;
1211
import org.togetherjava.tjbot.commands.system.BotCore;
1312
import org.togetherjava.tjbot.config.Config;
1413
import org.togetherjava.tjbot.db.Database;
15-
import org.togetherjava.tjbot.commands.SlashCommandAdapter;
1614

1715
import javax.security.auth.login.LoginException;
18-
1916
import java.io.IOException;
2017
import java.nio.file.Files;
2118
import java.nio.file.Path;
@@ -114,8 +111,7 @@ private static void onShutdown() {
114111
logger.info("Bot has been stopped");
115112
}
116113

117-
private static void onUncaughtException(@NotNull Thread failingThread,
118-
@NotNull Throwable failure) {
114+
private static void onUncaughtException(Thread failingThread, Throwable failure) {
119115
logger.error("Unknown error in thread {}.", failingThread.getName(), failure);
120116
}
121117

application/src/main/java/org/togetherjava/tjbot/commands/Features.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package org.togetherjava.tjbot.commands;
22

33
import net.dv8tion.jda.api.JDA;
4-
import org.jetbrains.annotations.NotNull;
54
import org.togetherjava.tjbot.commands.basic.PingCommand;
65
import org.togetherjava.tjbot.commands.basic.RoleSelectCommand;
76
import org.togetherjava.tjbot.commands.basic.SuggestionsUpDownVoter;
@@ -32,6 +31,7 @@
3231
import org.togetherjava.tjbot.moderation.ModAuditLogWriter;
3332
import org.togetherjava.tjbot.routines.ModAuditLogRoutine;
3433

34+
import javax.annotation.Nonnull;
3535
import java.util.ArrayList;
3636
import java.util.Collection;
3737

@@ -59,8 +59,8 @@ private Features() {
5959
* @param config the configuration features should use
6060
* @return a collection of all features
6161
*/
62-
public static @NotNull Collection<Feature> createFeatures(@NotNull JDA jda,
63-
@NotNull Database database, @NotNull Config config) {
62+
@Nonnull
63+
public static Collection<Feature> createFeatures(JDA jda, Database database, Config config) {
6464
TagSystem tagSystem = new TagSystem(database);
6565
ModerationActionsStore actionsStore = new ModerationActionsStore(database);
6666
ModAuditLogWriter modAuditLogWriter = new ModAuditLogWriter(config);

application/src/main/java/org/togetherjava/tjbot/commands/MessageReceiver.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
44
import net.dv8tion.jda.api.events.message.MessageUpdateEvent;
5-
import org.jetbrains.annotations.NotNull;
65

6+
import javax.annotation.Nonnull;
77
import java.util.regex.Pattern;
88

99
/**
@@ -28,7 +28,7 @@ public interface MessageReceiver extends Feature {
2828
*
2929
* @return the pattern matching the names of relevant channels
3030
*/
31-
@NotNull
31+
@Nonnull
3232
Pattern getChannelNamePattern();
3333

3434
/**
@@ -38,7 +38,7 @@ public interface MessageReceiver extends Feature {
3838
* @param event the event that triggered this, containing information about the corresponding
3939
* message that was sent and received
4040
*/
41-
void onMessageReceived(@NotNull MessageReceivedEvent event);
41+
void onMessageReceived(MessageReceivedEvent event);
4242

4343
/**
4444
* Triggered by the core system whenever an existing message was edited in a text channel of a
@@ -47,5 +47,5 @@ public interface MessageReceiver extends Feature {
4747
* @param event the event that triggered this, containing information about the corresponding
4848
* message that was edited
4949
*/
50-
void onMessageUpdated(@NotNull MessageUpdateEvent event);
50+
void onMessageUpdated(MessageUpdateEvent event);
5151
}

application/src/main/java/org/togetherjava/tjbot/commands/MessageReceiverAdapter.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
44
import net.dv8tion.jda.api.events.message.MessageUpdateEvent;
5-
import org.jetbrains.annotations.NotNull;
65

6+
import javax.annotation.Nonnull;
77
import java.util.regex.Pattern;
88

99
/**
@@ -24,24 +24,25 @@ public abstract class MessageReceiverAdapter implements MessageReceiver {
2424
* @param channelNamePattern the pattern matching names of channels interested in, only messages
2525
* from matching channels will be received
2626
*/
27-
protected MessageReceiverAdapter(@NotNull Pattern channelNamePattern) {
27+
protected MessageReceiverAdapter(Pattern channelNamePattern) {
2828
this.channelNamePattern = channelNamePattern;
2929
}
3030

3131
@Override
32-
public final @NotNull Pattern getChannelNamePattern() {
32+
@Nonnull
33+
public final Pattern getChannelNamePattern() {
3334
return channelNamePattern;
3435
}
3536

3637
@SuppressWarnings("NoopMethodInAbstractClass")
3738
@Override
38-
public void onMessageReceived(@NotNull MessageReceivedEvent event) {
39+
public void onMessageReceived(MessageReceivedEvent event) {
3940
// Adapter does not react by default, subclasses may change this behavior
4041
}
4142

4243
@SuppressWarnings("NoopMethodInAbstractClass")
4344
@Override
44-
public void onMessageUpdated(@NotNull MessageUpdateEvent event) {
45+
public void onMessageUpdated(MessageUpdateEvent event) {
4546
// Adapter does not react by default, subclasses may change this behavior
4647
}
4748
}

application/src/main/java/org/togetherjava/tjbot/commands/Routine.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package org.togetherjava.tjbot.commands;
22

33
import net.dv8tion.jda.api.JDA;
4-
import org.jetbrains.annotations.NotNull;
54

5+
import javax.annotation.Nonnull;
66
import java.util.concurrent.TimeUnit;
77

88
/**
@@ -24,15 +24,15 @@ public interface Routine extends Feature {
2424
*
2525
* @return the schedule of this routine
2626
*/
27-
@NotNull
27+
@Nonnull
2828
Schedule createSchedule();
2929

3030
/**
3131
* Triggered by the core system on the schedule defined by {@link #createSchedule()}.
3232
*
3333
* @param jda the JDA instance the bot is operating with
3434
*/
35-
void runRoutine(@NotNull JDA jda);
35+
void runRoutine(JDA jda);
3636

3737
/**
3838
* The schedule of routines.
@@ -46,8 +46,7 @@ public interface Routine extends Feature {
4646
* @param unit the time unit for both, {@link #initialDuration} and {@link #duration}, e.g.
4747
* seconds
4848
*/
49-
record Schedule(@NotNull ScheduleMode mode, long initialDuration, long duration,
50-
@NotNull TimeUnit unit) {
49+
record Schedule(ScheduleMode mode, long initialDuration, long duration, TimeUnit unit) {
5150
}
5251

5352

application/src/main/java/org/togetherjava/tjbot/commands/SlashCommand.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@
99
import net.dv8tion.jda.api.interactions.commands.build.SlashCommandData;
1010
import net.dv8tion.jda.api.interactions.components.ComponentInteraction;
1111
import net.dv8tion.jda.api.interactions.components.buttons.ButtonStyle;
12-
import org.jetbrains.annotations.NotNull;
1312
import org.togetherjava.tjbot.commands.componentids.ComponentId;
1413
import org.togetherjava.tjbot.commands.componentids.ComponentIdGenerator;
1514
import org.togetherjava.tjbot.commands.componentids.Lifespan;
1615

16+
import javax.annotation.Nonnull;
1717
import java.util.List;
1818

1919
/**
@@ -49,7 +49,7 @@ public interface SlashCommand extends UserInteractor {
4949
*
5050
* @return the description of the command
5151
*/
52-
@NotNull
52+
@Nonnull
5353
String getDescription();
5454

5555
/**
@@ -59,7 +59,7 @@ public interface SlashCommand extends UserInteractor {
5959
*
6060
* @return the visibility of the command
6161
*/
62-
@NotNull
62+
@Nonnull
6363
SlashCommandVisibility getVisibility();
6464

6565
/**
@@ -77,7 +77,7 @@ public interface SlashCommand extends UserInteractor {
7777
*
7878
* @return the command data of this command
7979
*/
80-
@NotNull
80+
@Nonnull
8181
SlashCommandData getData();
8282

8383
/**
@@ -118,5 +118,5 @@ public interface SlashCommand extends UserInteractor {
118118
*
119119
* @param event the event that triggered this
120120
*/
121-
void onSlashCommand(@NotNull SlashCommandInteractionEvent event);
121+
void onSlashCommand(SlashCommandInteractionEvent event);
122122
}

application/src/main/java/org/togetherjava/tjbot/commands/SlashCommandAdapter.java

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@
99
import net.dv8tion.jda.api.interactions.commands.build.Commands;
1010
import net.dv8tion.jda.api.interactions.commands.build.OptionData;
1111
import net.dv8tion.jda.api.interactions.commands.build.SlashCommandData;
12-
import org.jetbrains.annotations.NotNull;
1312
import org.jetbrains.annotations.Range;
1413
import org.jetbrains.annotations.Unmodifiable;
1514
import org.togetherjava.tjbot.commands.componentids.ComponentId;
1615
import org.togetherjava.tjbot.commands.componentids.ComponentIdGenerator;
1716
import org.togetherjava.tjbot.commands.componentids.Lifespan;
1817

18+
import javax.annotation.Nonnull;
1919
import java.util.Arrays;
2020
import java.util.List;
2121
import java.util.Objects;
@@ -55,7 +55,7 @@
5555
* }
5656
*
5757
* &#64;Override
58-
* public void onSlashCommand(@NotNull SlashCommandInteractionEvent event) {
58+
* public void onSlashCommand(SlashCommandInteractionEvent event) {
5959
* event.reply("Pong!").queue();
6060
* }
6161
* }
@@ -80,7 +80,7 @@ public abstract class SlashCommandAdapter implements SlashCommand {
8080
* {@link SlashCommandData#setDescription(String)}
8181
* @param visibility the visibility of the command
8282
*/
83-
protected SlashCommandAdapter(@NotNull String name, @NotNull String description,
83+
protected SlashCommandAdapter(String name, String description,
8484
SlashCommandVisibility visibility) {
8585
this.name = name;
8686
this.description = description;
@@ -90,40 +90,43 @@ protected SlashCommandAdapter(@NotNull String name, @NotNull String description,
9090
}
9191

9292
@Override
93-
public final @NotNull String getName() {
93+
@Nonnull
94+
public final String getName() {
9495
return name;
9596
}
9697

9798
@Override
98-
public final @NotNull String getDescription() {
99+
@Nonnull
100+
public final String getDescription() {
99101
return description;
100102
}
101103

102104
@Override
103-
public final @NotNull SlashCommandVisibility getVisibility() {
105+
@Nonnull
106+
public final SlashCommandVisibility getVisibility() {
104107
return visibility;
105108
}
106109

107110
@Override
108-
public final @NotNull SlashCommandData getData() {
111+
@Nonnull
112+
public final SlashCommandData getData() {
109113
return data;
110114
}
111115

112116
@Override
113-
public final void acceptComponentIdGenerator(@NotNull ComponentIdGenerator generator) {
117+
public final void acceptComponentIdGenerator(ComponentIdGenerator generator) {
114118
componentIdGenerator = generator;
115119
}
116120

117121
@SuppressWarnings("NoopMethodInAbstractClass")
118122
@Override
119-
public void onButtonClick(@NotNull ButtonInteractionEvent event, @NotNull List<String> args) {
123+
public void onButtonClick(ButtonInteractionEvent event, List<String> args) {
120124
// Adapter does not react by default, subclasses may change this behavior
121125
}
122126

123127
@SuppressWarnings("NoopMethodInAbstractClass")
124128
@Override
125-
public void onSelectionMenu(@NotNull SelectMenuInteractionEvent event,
126-
@NotNull List<String> args) {
129+
public void onSelectionMenu(SelectMenuInteractionEvent event, List<String> args) {
127130
// Adapter does not react by default, subclasses may change this behavior
128131
}
129132

@@ -142,7 +145,8 @@ public void onSelectionMenu(@NotNull SelectMenuInteractionEvent event,
142145
* @return the generated component ID
143146
*/
144147
@SuppressWarnings("OverloadedVarargsMethod")
145-
protected final @NotNull String generateComponentId(@NotNull String... args) {
148+
@Nonnull
149+
protected final String generateComponentId(String... args) {
146150
return generateComponentId(Lifespan.REGULAR, args);
147151
}
148152

@@ -159,8 +163,8 @@ public void onSelectionMenu(@NotNull SelectMenuInteractionEvent event,
159163
* @return the generated component ID
160164
*/
161165
@SuppressWarnings({"OverloadedVarargsMethod", "WeakerAccess"})
162-
protected final @NotNull String generateComponentId(@NotNull Lifespan lifespan,
163-
@NotNull String... args) {
166+
@Nonnull
167+
protected final String generateComponentId(Lifespan lifespan, String... args) {
164168
return Objects.requireNonNull(componentIdGenerator)
165169
.generate(new ComponentId(getName(), Arrays.asList(args)), lifespan);
166170
}
@@ -190,8 +194,9 @@ public void onSelectionMenu(@NotNull SelectMenuInteractionEvent event,
190194
* @return the generated list of options
191195
*/
192196
@Unmodifiable
193-
protected static @NotNull List<OptionData> generateMultipleOptions(
194-
@NotNull OptionData optionData, @Range(from = 1, to = 25) int amount) {
197+
@Nonnull
198+
protected static List<OptionData> generateMultipleOptions(OptionData optionData,
199+
@Range(from = 1, to = 25) int amount) {
195200
String baseName = optionData.getName();
196201

197202
Function<String, OptionData> nameToOption =
@@ -211,8 +216,9 @@ public void onSelectionMenu(@NotNull SelectMenuInteractionEvent event,
211216
* @return all options with the given prefix
212217
*/
213218
@Unmodifiable
214-
protected static @NotNull List<OptionMapping> getMultipleOptionsByNamePrefix(
215-
@NotNull CommandInteractionPayload event, @NotNull String namePrefix) {
219+
@Nonnull
220+
protected static List<OptionMapping> getMultipleOptionsByNamePrefix(
221+
CommandInteractionPayload event, String namePrefix) {
216222
return event.getOptions()
217223
.stream()
218224
.filter(option -> option.getName().startsWith(namePrefix))

0 commit comments

Comments
 (0)