|
1 | 1 | /* |
2 | | - * Copyright (c) 2012, 2021, Oracle and/or its affiliates. All rights reserved. |
| 2 | + * Copyright (c) 2012, 2024, Oracle and/or its affiliates. All rights reserved. |
3 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 | 4 | * |
5 | 5 | * This code is free software; you can redistribute it and/or modify it |
|
55 | 55 | private String fTargetClassName = "DummyClassWithLVT"; |
56 | 56 | private String classFileName = fTargetClassName + ".class"; |
57 | 57 | private boolean fTargetClassSeen; |
| 58 | + private Throwable transformerException; |
58 | 59 |
|
59 | 60 | /** |
60 | 61 | * Constructor for VerifyLocalVariableTableOnRetransformTest. |
@@ -109,9 +110,11 @@ public VerifyLocalVariableTableOnRetransformTest(String name) |
109 | 110 | // make an instance to prove the class was really loaded |
110 | 111 | Object testInstance = target.newInstance(); |
111 | 112 |
|
112 | | - // With this call here, we will see the target class once: |
113 | | - // when it gets retransformed. |
114 | | - //addTransformerToManager(fInst, new MyObserver(), true); |
| 113 | + // check for unexpected errors (see JDK-8311534) |
| 114 | + if (transformerException != null) { |
| 115 | + transformerException.printStackTrace(); |
| 116 | + throw new RuntimeException("Error in transformer" + transformerException); |
| 117 | + } |
115 | 118 |
|
116 | 119 | assertTrue(fTargetClassName + " was not seen by transform()", |
117 | 120 | fTargetClassSeen); |
@@ -247,8 +250,20 @@ private void saveMismatchedBytes(byte[] classfileBuffer) { |
247 | 250 | ProtectionDomain protectionDomain, |
248 | 251 | byte[] classfileBuffer) { |
249 | 252 |
|
250 | | - System.out.println(this + ".transform() sees '" + className |
251 | | - + "' of " + classfileBuffer.length + " bytes."); |
| 253 | + // String concatenation can cause LinkageError or ClassCircularityError (see JDK-8311534). |
| 254 | + // Need to log it for analysis. |
| 255 | + try { |
| 256 | + System.out.println(this + ".transform() sees '" + className |
| 257 | + + "' of " + classfileBuffer.length + " bytes."); |
| 258 | + } catch (Throwable t) { |
| 259 | + // Try to log. Save the error for handling by main thread if the logging fails. |
| 260 | + try { |
| 261 | + t.printStackTrace(); |
| 262 | + } catch (Throwable t1) { |
| 263 | + transformerException = t; |
| 264 | + } |
| 265 | + return null; |
| 266 | + } |
252 | 267 | if (className.equals(fTargetClassName)) { |
253 | 268 | fTargetClassSeen = true; |
254 | 269 |
|
|
0 commit comments