Skip to content

Commit 0aeffc9

Browse files
authored
fix bug of viewing enum obj (#3041)
1 parent 2b97ca8 commit 0aeffc9

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

core/src/main/java/com/taobao/arthas/core/view/ObjectView.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -587,7 +587,7 @@ else if (Date.class.isInstance(obj)) {
587587
appendStringBuilder(buf, format("@%s[%s]", className, new SimpleDateFormat("yyyy-MM-dd HH:mm:ss,SSS").format(obj)));
588588
}
589589

590-
else if (object instanceof Enum<?>) {
590+
else if (obj instanceof Enum<?>) {
591591
appendStringBuilder(buf, format("@%s[%s]", className, obj));
592592
}
593593

core/src/test/java/com/taobao/arthas/core/view/ObjectViewTest.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,23 @@ public void testThrowable() {
189189
Assert.assertTrue(objectView.draw().startsWith("java.lang.Exception: test"));
190190
}
191191

192+
@Test
193+
public void testEnum() {
194+
EnumDemo t = EnumDemo.DEMO;
195+
ObjectView objectView = new ObjectView(t, 3);
196+
Assert.assertEquals("@EnumDemo[DEMO]", objectView.draw());
197+
}
198+
199+
@Test
200+
public void testEnumList() {
201+
EnumDemo t = EnumDemo.DEMO;
202+
ObjectView objectView = new ObjectView(new Object[] {t}, 3);
203+
String expected = "@Object[][\n" +
204+
" @EnumDemo[DEMO],\n" +
205+
"]";
206+
Assert.assertEquals(expected, objectView.draw());
207+
}
208+
192209
@Test
193210
public void testDate() {
194211
Date d = new Date(1531204354961L - TimeZone.getDefault().getRawOffset()
@@ -303,4 +320,8 @@ public void setJ(String j) {
303320
this.j = j;
304321
}
305322
}
323+
324+
public enum EnumDemo {
325+
DEMO;
326+
}
306327
}

0 commit comments

Comments
 (0)