Skip to content

Commit eec0e15

Browse files
committed
8335619: Add an @APinote to j.l.i.ClassFileTransformer to warn about recursive class loading and ClassCircularityErrors
Reviewed-by: alanb, stuefe, liach
1 parent 9b6f6c5 commit eec0e15

File tree

1 file changed

+21
-4
lines changed

1 file changed

+21
-4
lines changed

src/java.instrument/share/classes/java/lang/instrument/ClassFileTransformer.java

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2003, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2003, 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
@@ -155,11 +155,28 @@
155155
* logging or debugging of format corruptions.
156156
*
157157
* <P>
158-
* Note the term <i>class file</i> is used as defined in section 3.1 of
159-
* <cite>The Java Virtual Machine Specification</cite>, to mean a
160-
* sequence of bytes in class file format, whether or not they reside in a
158+
* Note the term <i>class file</i> is used as defined in chapter {@jvms 4} The
159+
* {@code class} File Format of <cite>The Java Virtual Machine Specification</cite>,
160+
* to mean a sequence of bytes in class file format, whether or not they reside in a
161161
* file.
162162
*
163+
* @apiNote
164+
* Great care must be taken when transforming core JDK classes which are at the
165+
* same time required during the transformation process as this can lead to class
166+
* circularity or linkage errors.
167+
*
168+
* <P>
169+
* If for example the invocation of {@link #transform transform()} for a class
170+
* {@code C} requires loading or resolving the same class {@code C},
171+
* an error is thrown that is an instance of {@link LinkageError} (or a subclass).
172+
* If the {@link LinkageError} occurs during reference resolution (see section
173+
* {@jvms 5.4.3} Resolution of <cite>The Java Virtual Machine Specification</cite>)
174+
* for a class {@code D}, the resolution of the corresponding reference in class
175+
* {@code D} will permanently fail with the same error at any subsequent attempt.
176+
* This means that a {@link LinkageError} triggered during transformation of
177+
* {@code C} in a class {@code D} not directly related to {@code C} can repeatedly
178+
* occur later in arbitrary user code which uses {@code D}.
179+
*
163180
* @see java.lang.instrument.Instrumentation
164181
* @since 1.5
165182
*/

0 commit comments

Comments
 (0)