Skip to content

Commit c0f0b8e

Browse files
author
Alex Menkov
committed
8346151: Add transformer error logging to VerifyLocalVariableTableOnRetransformTest
Reviewed-by: cjplummer, sspitsyn
1 parent f3e2f88 commit c0f0b8e

File tree

1 file changed

+21
-6
lines changed

1 file changed

+21
-6
lines changed

test/jdk/java/lang/instrument/VerifyLocalVariableTableOnRetransformTest.java

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
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.
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
@@ -55,6 +55,7 @@
5555
private String fTargetClassName = "DummyClassWithLVT";
5656
private String classFileName = fTargetClassName + ".class";
5757
private boolean fTargetClassSeen;
58+
private Throwable transformerException;
5859

5960
/**
6061
* Constructor for VerifyLocalVariableTableOnRetransformTest.
@@ -109,9 +110,11 @@ public VerifyLocalVariableTableOnRetransformTest(String name)
109110
// make an instance to prove the class was really loaded
110111
Object testInstance = target.newInstance();
111112

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+
}
115118

116119
assertTrue(fTargetClassName + " was not seen by transform()",
117120
fTargetClassSeen);
@@ -247,8 +250,20 @@ private void saveMismatchedBytes(byte[] classfileBuffer) {
247250
ProtectionDomain protectionDomain,
248251
byte[] classfileBuffer) {
249252

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+
}
252267
if (className.equals(fTargetClassName)) {
253268
fTargetClassSeen = true;
254269

0 commit comments

Comments
 (0)