8339587: runtime/reflect/ReflectOutOfMemoryError.java fails with "bootstrap method initialization exception"

Reviewed-by: lmesnik, ccheung
This commit is contained in:
David Holmes 2024-09-10 08:22:25 +00:00
parent 125f743223
commit 64de7813e4

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2023, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -88,15 +88,24 @@ public class ReflectOutOfMemoryError {
Object junk = testMethod.invoke(null, new Object [0]); Object junk = testMethod.invoke(null, new Object [0]);
throw new RuntimeException("InvocationTargetException should be thrown"); throw new RuntimeException("InvocationTargetException should be thrown");
} catch (InvocationTargetException ite) { } catch (InvocationTargetException ite) {
Throwable targetException = ite.getTargetException(); // We may not directly get OOME but it could have caused
if (targetException instanceof OutOfMemoryError) { // secondary exceptions, so walk the chain of exceptions
System.out.println("OutOfMemoryError thrown as expected."); // and see if there is an OOME somewhere.
System.out.println("Test passed."); for (Throwable cause = ite.getTargetException();
} else { cause != null;
throw new RuntimeException("Unexpected InvocationTargetException: " + targetException); cause = cause.getCause()) {
if (cause instanceof OutOfMemoryError) {
System.out.println("OutOfMemoryError thrown as expected.");
ite.printStackTrace(System.out);
System.out.println("Test passed.");
return;
}
} }
throw new RuntimeException("Unexpected InvocationTargetException: ",
ite.getTargetException());
} catch (Exception exception) { } catch (Exception exception) {
throw new RuntimeException("Unexpected exception: " + exception); throw new RuntimeException("Unexpected exception: ", exception);
} }
} }
} }