Skip to content

Commit

Permalink
errorprone :: update UnusedException messages (#895)
Browse files Browse the repository at this point in the history
  • Loading branch information
jpdahlke authored Aug 29, 2024
1 parent c792bcb commit ae17598
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public void trigger(Map<String, Sentinel.Tracker> tracker) {
logger.warn("Sentinel attempting recovery for {}", agentName);
mobileAgent.interrupt();
} catch (Exception e) {
throw new IllegalStateException("Recovery unavailable ", e);
throw new IllegalStateException("Recovery unavailable", e);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/emissary/util/magic/MagicNumberFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ private static int resolveOffset(String[] columns, MagicNumber item) throws Pars
try {
return MagicMath.stringToInt(entry);
} catch (NumberFormatException e) {
throw new ParseException(e + ": Malformatted offset value: " + entry);
throw new ParseException(e + ": Malformed offset value");
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/emissary/util/search/ByteTokenizer.java
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ public ByteTokenizer(byte[] bytes, int start, int len, String delim, boolean ret
try {
Charset c = Charset.forName(encoding);
logger.debug("Loaded charset {}", c);
} catch (Exception ex) {
throw new UnsupportedEncodingException(ex + ": No support for " + encoding);
} catch (IllegalArgumentException ex) {
throw new UnsupportedEncodingException(ex.toString());
}
this.encoding = encoding;
}
Expand Down
22 changes: 22 additions & 0 deletions src/test/java/emissary/util/magic/MagicMathTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package emissary.util.magic;

import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;

class MagicMathTest {

@Test
void testStringToInt() {
int x = MagicMath.stringToInt("13");
assertEquals(13, x);

// existing behavior
assertThrows(NullPointerException.class, () -> MagicMath.stringToInt(null));

String entry = "blah";
Exception exception = assertThrows(NumberFormatException.class, () -> MagicMath.stringToInt(entry));
assertEquals("java.lang.NumberFormatException: For input string: \"blah\"", exception.toString());
}
}
25 changes: 25 additions & 0 deletions src/test/java/emissary/util/search/ByteTokenizerTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package emissary.util.search;

import org.junit.jupiter.api.Test;

import java.io.UnsupportedEncodingException;
import java.nio.charset.StandardCharsets;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;

class ByteTokenizerTest {

@Test
void testEncodingConstructor() throws Exception {

byte[] testBytes = "these are test bytes".getBytes(StandardCharsets.UTF_8);
ByteTokenizer byteTokenizer = new ByteTokenizer(testBytes, 0, 12, " ", StandardCharsets.UTF_8.name());
assertEquals(3, byteTokenizer.countTokens());

assertThrows(UnsupportedEncodingException.class, () -> new ByteTokenizer(testBytes, 0, 12, " ", null));

Exception exception = assertThrows(UnsupportedEncodingException.class, () -> new ByteTokenizer(testBytes, 0, 12, " ", "fake-encoding"));
assertEquals("java.io.UnsupportedEncodingException: java.nio.charset.UnsupportedCharsetException: fake-encoding", exception.toString());
}
}

0 comments on commit ae17598

Please sign in to comment.