Skip to content

Commit

Permalink
Eliminate warnings.
Browse files Browse the repository at this point in the history
Updated some SDK code to avoid warning messages from code scanning
tools. This includes a change to the StringReader#skip method, which now
explicitly checks for negative values.

JiraIssue: DS-48860
  • Loading branch information
kqarryzada committed May 17, 2024
1 parent 2f6ec9b commit d5c2e1f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ private static final class StringReader extends Reader
{
@NotNull
private final String string;

private int pos;
private int mark;

Expand Down Expand Up @@ -122,12 +123,23 @@ public void reset()

/**
* {@inheritDoc}
*
* @throws IllegalArgumentException If {@code n} is negative.
*/
@Override
public long skip(final long n)
public long skip(final long n) throws IllegalArgumentException
{
if (n < 0L)
{
throw new IllegalArgumentException(
"Attempted to skip a negative number of characters.");
}
long chars = Math.min(string.length() - pos, n);
pos += chars;

// The left side of Math.min() is an integer, and 'chars' will always be
// non-negative, so 'chars' can always be represented as an int.
pos += (int) chars;

return chars;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,12 @@
import java.util.List;
import java.util.Objects;
import java.util.Set;
import java.util.regex.Pattern;

/**
* This class provides a number of static utility functions.
*/
public final class StaticUtils
{
@NotNull
private static final Pattern SEPARATOR = Pattern.compile("\\s*,\\s*");

/**
* Prevent this class from being instantiated.
*/
Expand Down Expand Up @@ -240,7 +236,13 @@ public static <T> Set<T> arrayToSet(@NotNull final T... i)
@NotNull
public static String[] splitCommaSeparatedString(@NotNull final String str)
{
return SEPARATOR.split(str.trim());
String[] separatedArray = str.split(",");
for (int i = 0; i < separatedArray.length; i++)
{
separatedArray[i] = separatedArray[i].trim();
}

return separatedArray;
}


Expand Down

0 comments on commit d5c2e1f

Please sign in to comment.