src/share/classes/sun/misc/ClassFileTransformer.java
Print this page
@@ -23,62 +23,48 @@
* questions.
*/
package sun.misc;
import java.util.ArrayList;
+import java.util.List;
/**
- * This is an abstract base class which is called by java.lang.ClassLoader
- * when ClassFormatError is thrown inside defineClass().
- *
- * The purpose of this class is to allow applications (e.g. Java Plug-in)
- * to have a chance to transform the byte code from one form to another
- * if necessary.
- *
- * One application of this class is used by Java Plug-in to transform
- * malformed JDK 1.1 class file into a well-formed Java 2 class file
- * on-the-fly, so JDK 1.1 applets with malformed class file in the
- * Internet may run in Java 2 after transformation.
+ * This is an abstract base class originally intended to be called by
+ * {@code java.lang.ClassLoader} when {@code ClassFormatError} is
+ * thrown inside {@code defineClass()}. It is no longer hooked into
+ * {@code ClassLoader} and will be removed in a future release.
*
* @author Stanley Man-Kit Ho
*/
-public abstract class ClassFileTransformer
-{
- // Singleton of ClassFileTransformer
- //
- private static ArrayList<ClassFileTransformer> transformerList
+@Deprecated
+public abstract class ClassFileTransformer {
+
+ private static final List<ClassFileTransformer> transformers
= new ArrayList<ClassFileTransformer>();
- private static ClassFileTransformer[] transformers
- = new ClassFileTransformer[0];
/**
* Add the class file transformer object.
*
* @param t Class file transformer instance
*/
- public static void add(ClassFileTransformer t)
- {
- synchronized(transformerList)
- {
- transformerList.add(t);
- transformers = transformerList.toArray(new ClassFileTransformer[0]);
+ public static void add(ClassFileTransformer t) {
+ synchronized (transformers) {
+ transformers.add(t);
}
}
/**
* Get the array of ClassFileTransformer object.
*
* @return ClassFileTransformer object array
*/
- public static ClassFileTransformer[] getTransformers()
- {
- // transformers is not intended to be changed frequently,
- // so it is okay to not put synchronized block here
- // to speed up performance.
- //
- return transformers;
+ public static ClassFileTransformer[] getTransformers() {
+ synchronized (transformers) {
+ ClassFileTransformer[] result = new ClassFileTransformer[transformers.size()];
+ return transformers.toArray(result);
+ }
}
/**
* Transform a byte array from one to the other.