Skip to content

Commit 9142d0c

Browse files
committed
Fix ExceptionsTable when stacktrace has zero elements
patch by Stefan Miklosovic; reviewed by Brandon Williams, Dmitry Konstantinov for CASSANDRA-20992
1 parent 8093847 commit 9142d0c

File tree

3 files changed

+33
-2
lines changed

3 files changed

+33
-2
lines changed

CHANGES.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
5.1
2+
* Fix ExceptionsTable when stacktrace has zero elements (CASSANDRA-20992)
23
* Replace blocking wait with non-blocking delay in paxos repair (CASSANDRA-20983)
34
* Implementation of CEP-55 - Generation of role names (CASSANDRA-20897)
45
* Add cqlsh autocompletion for the identity mapping feature (CASSANDRA-20021)

src/java/org/apache/cassandra/db/virtual/ExceptionsTable.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,15 +171,15 @@ public static void persist(Throwable t)
171171
if (INSTANCE != null)
172172
{
173173
INSTANCE.add(toPersist.getClass().getName(),
174-
stackTrace.get(0),
174+
stackTrace.isEmpty() ? "unknown" : stackTrace.get(0),
175175
toPersist.getMessage(),
176176
stackTrace,
177177
now);
178178
}
179179
else
180180
{
181181
preInitialisationBuffer.add(new ExceptionRow(toPersist.getClass().getName(),
182-
stackTrace.get(0),
182+
stackTrace.isEmpty() ? "unknown" : stackTrace.get(0),
183183
0,
184184
toPersist.getMessage(),
185185
stackTrace,

test/unit/org/apache/cassandra/db/virtual/ExceptionsTableTest.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,28 @@ public void testTruncation()
264264
});
265265
}
266266

267+
@Test
268+
public void testEmptyStacktrace()
269+
{
270+
doWithVTable(4, table ->
271+
{
272+
// register after treating exception, so it goes to pre-initialisation buffer first
273+
VirtualKeyspaceRegistry.instance.register(new VirtualKeyspace(KS_NAME, ImmutableList.of(table)));
274+
ExceptionsTable.INSTANCE = getVirtualTable(ExceptionsTable.class, KS_NAME, EXCEPTIONS_TABLE_NAME);
275+
276+
JVMStabilityInspector.uncaughtException(currentThread(), new MyUncaughtExceptionWithoutStacktrace("my exception"));
277+
278+
ExceptionsTable.BoundedMap buffer = table.buffer;
279+
assertEquals(1, buffer.size());
280+
281+
LinkedHashMap<String, ExceptionRow> partition = buffer.get(MyUncaughtExceptionWithoutStacktrace.class.getName());
282+
ExceptionRow clustering = partition.get("unknown");
283+
assertNotNull(clustering);
284+
assertEquals(1, clustering.count);
285+
assertEquals("my exception", clustering.message);
286+
});
287+
}
288+
267289
private List<UntypedResultSet.Row> rows(String query)
268290
{
269291
return execute(query).stream().collect(toList());
@@ -306,4 +328,12 @@ public MyUncaughtException2(String message)
306328
super(message);
307329
}
308330
}
331+
332+
public static class MyUncaughtExceptionWithoutStacktrace extends Throwable
333+
{
334+
public MyUncaughtExceptionWithoutStacktrace(String message)
335+
{
336+
super(message, null, false, false);
337+
}
338+
}
309339
}

0 commit comments

Comments
 (0)