Skip to content

Commit 64de781

Browse files
author
David Holmes
committedSep 10, 2024
8339587: runtime/reflect/ReflectOutOfMemoryError.java fails with "bootstrap method initialization exception"
Reviewed-by: lmesnik, ccheung
1 parent 125f743 commit 64de781

File tree

1 file changed

+17
-8
lines changed

1 file changed

+17
-8
lines changed
 

‎test/hotspot/jtreg/runtime/reflect/ReflectOutOfMemoryError.java

+17-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2023, 2024, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -88,15 +88,24 @@ public static void main(java.lang.String[] unused) throws Exception {
8888
Object junk = testMethod.invoke(null, new Object [0]);
8989
throw new RuntimeException("InvocationTargetException should be thrown");
9090
} catch (InvocationTargetException ite) {
91-
Throwable targetException = ite.getTargetException();
92-
if (targetException instanceof OutOfMemoryError) {
93-
System.out.println("OutOfMemoryError thrown as expected.");
94-
System.out.println("Test passed.");
95-
} else {
96-
throw new RuntimeException("Unexpected InvocationTargetException: " + targetException);
91+
// We may not directly get OOME but it could have caused
92+
// secondary exceptions, so walk the chain of exceptions
93+
// and see if there is an OOME somewhere.
94+
for (Throwable cause = ite.getTargetException();
95+
cause != null;
96+
cause = cause.getCause()) {
97+
if (cause instanceof OutOfMemoryError) {
98+
System.out.println("OutOfMemoryError thrown as expected.");
99+
ite.printStackTrace(System.out);
100+
System.out.println("Test passed.");
101+
return;
102+
}
97103
}
104+
105+
throw new RuntimeException("Unexpected InvocationTargetException: ",
106+
ite.getTargetException());
98107
} catch (Exception exception) {
99-
throw new RuntimeException("Unexpected exception: " + exception);
108+
throw new RuntimeException("Unexpected exception: ", exception);
100109
}
101110
}
102111
}

0 commit comments

Comments
 (0)
Please sign in to comment.