Skip to content

Commit

Permalink
Fix format specifiers when adding invalid choices (#2628)
Browse files Browse the repository at this point in the history
  • Loading branch information
freya022 committed Mar 30, 2024
1 parent 2b82a62 commit ce6e2e2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
Expand Up @@ -69,21 +69,21 @@ public AutoCompleteCallbackAction addChoices(@Nonnull Collection<Command.Choice>
"Choice of type %s cannot be converted to INTEGER", choice.getType());
long valueLong = choice.getAsLong();
Checks.check(valueLong <= OptionData.MAX_POSITIVE_NUMBER,
"Choice value cannot be larger than %d Provided: %d",
"Choice value cannot be larger than %f Provided: %d",
OptionData.MAX_POSITIVE_NUMBER, valueLong);
Checks.check(valueLong >= OptionData.MIN_NEGATIVE_NUMBER,
"Choice value cannot be smaller than %d. Provided: %d",
"Choice value cannot be smaller than %f. Provided: %d",
OptionData.MIN_NEGATIVE_NUMBER, valueLong);
break;
case NUMBER:
Checks.check(choice.getType() == OptionType.NUMBER || choice.getType() == OptionType.INTEGER,
"Choice of type %s cannot be converted to NUMBER", choice.getType());
double valueDouble = choice.getAsDouble();
Checks.check(valueDouble <= OptionData.MAX_POSITIVE_NUMBER,
"Choice value cannot be larger than %d Provided: %d",
"Choice value cannot be larger than %f Provided: %f",
OptionData.MAX_POSITIVE_NUMBER, valueDouble);
Checks.check(valueDouble >= OptionData.MIN_NEGATIVE_NUMBER,
"Choice value cannot be smaller than %d. Provided: %d",
"Choice value cannot be smaller than %f. Provided: %f",
OptionData.MIN_NEGATIVE_NUMBER, valueDouble);
break;
case STRING:
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/net/dv8tion/jda/internal/utils/Checks.java
Expand Up @@ -25,6 +25,7 @@
import net.dv8tion.jda.api.interactions.components.ActionComponent;
import net.dv8tion.jda.api.interactions.components.Component;
import net.dv8tion.jda.api.interactions.components.LayoutComponent;
import org.intellij.lang.annotations.PrintFormat;
import org.jetbrains.annotations.Contract;

import java.util.*;
Expand Down Expand Up @@ -63,14 +64,14 @@ public static void check(final boolean expression, final String message)
}

@Contract("false, _, _ -> fail")
public static void check(final boolean expression, final String message, final Object... args)
public static void check(final boolean expression, @PrintFormat final String message, final Object... args)
{
if (!expression)
throw new IllegalArgumentException(String.format(message, args));
}

@Contract("false, _, _ -> fail")
public static void check(final boolean expression, final String message, final Object arg)
public static void check(final boolean expression, @PrintFormat final String message, final Object arg)
{
if (!expression)
throw new IllegalArgumentException(String.format(message, arg));
Expand Down

0 comments on commit ce6e2e2

Please sign in to comment.