Skip to content

Commit 4d50239

Browse files
committed
Avoid ArrayIndexOutOfBoundsException in EmitLogDirect
It is true that the EmitLogDirect.getMessage() method only calls the EmitLogDirect.joinStrings() method when the length of the strings array argument is at least 2. However, it is safe make our method more robust by avoiding the ArrayIndexOutOfBoundsException exception as much as we can. Who knows? Maybe the EmitLogDirect.joinStrings() method could be extracted in a utility class and used in cases where the startIndex could potentially be equal to the length of the passed array.
1 parent 6721db8 commit 4d50239

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

java/EmitLogDirect.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ private static String getMessage(String[] strings) {
3737
private static String joinStrings(String[] strings, String delimiter, int startIndex) {
3838
int length = strings.length;
3939
if (length == 0) return "";
40-
if (length < startIndex) return "";
40+
if (length <= startIndex) return "";
4141
StringBuilder words = new StringBuilder(strings[startIndex]);
4242
for (int i = startIndex + 1; i < length; i++) {
4343
words.append(delimiter).append(strings[i]);

0 commit comments

Comments
 (0)