harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From py...@apache.org
Subject svn commit: r429287 - in /incubator/harmony/enhanced/classlib/trunk/modules/instrument/src: main/java/java/lang/instrument/ test/java/org/ test/java/org/apache/ test/java/org/apache/harmony/ test/java/org/apache/harmony/tests/ test/java/org/apache/harm...
Date Mon, 07 Aug 2006 09:52:11 GMT
Author: pyang
Date: Mon Aug  7 02:52:06 2006
New Revision: 429287

URL: http://svn.apache.org/viewvc?rev=429287&view=rev
Log:
Fix for HARMONY-1065, HARMONY-1071, HARMONY-1072, HARMONY-1074, HARMONY-1078 (Several simple
new classes/interfaces of instrument module)

Added:
    incubator/harmony/enhanced/classlib/trunk/modules/instrument/src/main/java/java/lang/instrument/ClassDefinition.java
    incubator/harmony/enhanced/classlib/trunk/modules/instrument/src/main/java/java/lang/instrument/ClassFileTransformer.java
    incubator/harmony/enhanced/classlib/trunk/modules/instrument/src/main/java/java/lang/instrument/IllegalClassFormatException.java
    incubator/harmony/enhanced/classlib/trunk/modules/instrument/src/main/java/java/lang/instrument/Instrumentation.java
    incubator/harmony/enhanced/classlib/trunk/modules/instrument/src/main/java/java/lang/instrument/UnmodifiableClassException.java
    incubator/harmony/enhanced/classlib/trunk/modules/instrument/src/test/java/org/
    incubator/harmony/enhanced/classlib/trunk/modules/instrument/src/test/java/org/apache/
    incubator/harmony/enhanced/classlib/trunk/modules/instrument/src/test/java/org/apache/harmony/
    incubator/harmony/enhanced/classlib/trunk/modules/instrument/src/test/java/org/apache/harmony/tests/
    incubator/harmony/enhanced/classlib/trunk/modules/instrument/src/test/java/org/apache/harmony/tests/java/
    incubator/harmony/enhanced/classlib/trunk/modules/instrument/src/test/java/org/apache/harmony/tests/java/lang/
    incubator/harmony/enhanced/classlib/trunk/modules/instrument/src/test/java/org/apache/harmony/tests/java/lang/instrument/
    incubator/harmony/enhanced/classlib/trunk/modules/instrument/src/test/java/org/apache/harmony/tests/java/lang/instrument/ClassDefinitionTest.java

Added: incubator/harmony/enhanced/classlib/trunk/modules/instrument/src/main/java/java/lang/instrument/ClassDefinition.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/instrument/src/main/java/java/lang/instrument/ClassDefinition.java?rev=429287&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/instrument/src/main/java/java/lang/instrument/ClassDefinition.java
(added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/instrument/src/main/java/java/lang/instrument/ClassDefinition.java
Mon Aug  7 02:52:06 2006
@@ -0,0 +1,78 @@
+/* Copyright 2006 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package java.lang.instrument;
+
+/**
+ * Wraps a {@link java.lang.Class} that is to be redefined together with the
+ * byte array which constitutes the updated version of the class.
+ * 
+ */
+public final class ClassDefinition {
+
+    /**
+     * The <code>Class</code> object for the class that will be instrumented.
+     */
+    private Class<?> definitionClass;
+
+    /**
+     * The new version of the class file bytes for the class being instrumented.
+     */
+    private byte[] definitionClassFile;
+
+    /**
+     * Constructs a new instance of <code>ClassDefinition</code> with the
+     * supplied {@link Class} object and byte array representing the new class
+     * file bytes.
+     * 
+     * @param theClass
+     *            the <code>Class</code> object for the class to be redefined
+     * @param theClassFile
+     *            an array of bytes containing the updated version of the class
+     *            to be redefined.
+     * @throws NullPointerException
+     *             if either <code>theClass</code> or
+     *             <code>theClassFile</code> are <code>null</code>.
+     */
+    public ClassDefinition(Class<?> theClass, byte[] theClassFile) {
+        if (theClass == null) {
+            throw new NullPointerException("Received null class argument.");
+        }
+        if (theClassFile == null) {
+            throw new NullPointerException("Received null class file argument.");
+        }
+        this.definitionClass = theClass;
+        this.definitionClassFile = theClassFile;
+    }
+
+    /**
+     * Returns the {@link Class} object for the class to be redefined.
+     * 
+     * @return the <code>Class</code> object
+     */
+    public Class<?> getDefinitionClass() {
+        return this.definitionClass;
+    }
+
+    /**
+     * Returns a reference to the byte array containing the re-engineered
+     * version of the class.
+     * 
+     * @return byte array containing the new version of the class
+     */
+    public byte[] getDefinitionClassFile() {
+        return this.definitionClassFile;
+    }
+}

Added: incubator/harmony/enhanced/classlib/trunk/modules/instrument/src/main/java/java/lang/instrument/ClassFileTransformer.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/instrument/src/main/java/java/lang/instrument/ClassFileTransformer.java?rev=429287&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/instrument/src/main/java/java/lang/instrument/ClassFileTransformer.java
(added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/instrument/src/main/java/java/lang/instrument/ClassFileTransformer.java
Mon Aug  7 02:52:06 2006
@@ -0,0 +1,100 @@
+/* Copyright 2006 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package java.lang.instrument;
+
+import java.security.ProtectionDomain;
+
+/**
+ * This interface must be implemented by types used to instrument classes as
+ * they are loaded by a running VM. Implementations are registered by agents in
+ * the {@link java.lang.instrument.Instrumentation#addTransformer} operation.
+ * Once registered, a <code>ClassFileTransformer</code> has the opportunity to
+ * instrument every class that is loaded or redefined by the VM provided that
+ * the transformer does not have a dependency on that class.
+ * <p>
+ * Transformations of classes takes place just prior to them being defined by
+ * the VM.
+ * </p>
+ * 
+ */
+public interface ClassFileTransformer {
+
+    /**
+     * Receives a <code>byte</code> array containing the raw contents of a
+     * class for <i>possible</i> transformation into a new <code>byte</code>
+     * array which gets returned to the caller. It is left up to the
+     * implementation to decide what, if any, transformations are carried out
+     * and returned.
+     * <p>
+     * Requests for class transformations can occur in two situations.
+     * <ul>
+     * <li>the attempted defining of a class using
+     * {@link ClassLoader#defineClass(java.lang.String, byte[], int, int)}
+     * <li>the attempted re-defining of a previously defined class using
+     * {@link Instrumentation#redefineClasses(ClassDefinition[])}
+     * </ul>
+     * In both cases this operation will be called before the verification of
+     * the specified bytes in the <code>Class</code> file format. Each
+     * registered <code>ClassFileTransformer</code> instance will have this
+     * operation called on it. The order of the invocations matches the order in
+     * which the transformers were registered using the method
+     * {@link Instrumentation#addTransformer(ClassFileTransformer)}.
+     * </p>
+     * <p>
+     * Provided that the implementation of this method wishes to carry out a
+     * transformation, the return is a newly allocated <code>byte</code> array
+     * which contains <i>a copy of</i> the <code>classfileBuffer</code>
+     * argument plus the transformations to the array specific to the method
+     * implementation. If the transformer is written so as to pass on the
+     * opportunity to modify a given input then the return value should be
+     * <code>null</code>.
+     * </p>
+     * 
+     * @param loader
+     *            the <i>defining</i> <code>ClassLoader</code> for
the
+     *            candidate class to be transformed.
+     * @param className
+     *            the fully qualified name of the candidate class to be
+     *            transformed in the <i>fully/qualified/Name</i> format.
+     * @param classBeingRedefined
+     *            if a class redefinition is in process then this argument will
+     *            be the <code>Class</code> object for the class. Otherwise,
+     *            if a class definition is in process, a <code>null</code>.
+     * @param protectionDomain
+     *            the security protection domain for the class being defined or
+     *            redefined.
+     * @param classfileBuffer
+     *            a <code>byte</code> array containing the class to be
+     *            transformed in <code>Class</code> file format.
+     *            <em>This argument
+     *            must not be modified</em>.
+     * @return if transformation occurs, a newly allocated <code>byte</code>
+     *         array containing the modified version of
+     *         <code>classfileBuffer</code>, otherwise <code>null</code>.
+     * @throws IllegalClassFormatException
+     *             if the <code>classfileBuffer</code> does not contain a
+     *             well-formed representation of a class in the
+     *             <code>Class</code> file format. Note that if an invocation
+     *             of this operation ends on an exception throw then (a) the
+     *             remaining transformers in the &quot;chain&quot; will still
+     *             have this method called, and (b) the class definition or
+     *             redefinition that was the catalyst for the transformation
+     *             opportunities will still be attempted.
+     */
+    public byte[] transform(ClassLoader loader, String className,
+            Class classBeingRedefined, ProtectionDomain protectionDomain,
+            byte[] classfileBuffer) throws IllegalClassFormatException;
+}

Added: incubator/harmony/enhanced/classlib/trunk/modules/instrument/src/main/java/java/lang/instrument/IllegalClassFormatException.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/instrument/src/main/java/java/lang/instrument/IllegalClassFormatException.java?rev=429287&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/instrument/src/main/java/java/lang/instrument/IllegalClassFormatException.java
(added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/instrument/src/main/java/java/lang/instrument/IllegalClassFormatException.java
Mon Aug  7 02:52:06 2006
@@ -0,0 +1,48 @@
+/* Copyright 2006 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package java.lang.instrument;
+
+/**
+ * This exception may be thrown from implementations of the method
+ * {@link java.lang.instrument.ClassFileTransformer#transform} when the class
+ * file bytes supplied to it are found to be corrupted or otherwise in a format
+ * which does not adhere to the expected Java class file format.
+ * 
+ */
+public class IllegalClassFormatException extends Exception {
+
+    private static final long serialVersionUID = -3841736710924794009L;
+
+    /**
+     * Constructs a new instance of <code>IllegalClassFormatException</code>
+     * with no explanatory message.
+     */
+    public IllegalClassFormatException() {
+        super();
+    }
+
+    /**
+     * Constructs a new instance of <code>IllegalClassFormatException</code>
+     * with the supplied message, <code>s</code>, for explanation.
+     * 
+     * @param s
+     *            a string containing information on why the exception is being
+     *            created.
+     */
+    public IllegalClassFormatException(String s) {
+        super(s);
+    }
+}
\ No newline at end of file

Added: incubator/harmony/enhanced/classlib/trunk/modules/instrument/src/main/java/java/lang/instrument/Instrumentation.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/instrument/src/main/java/java/lang/instrument/Instrumentation.java?rev=429287&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/instrument/src/main/java/java/lang/instrument/Instrumentation.java
(added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/instrument/src/main/java/java/lang/instrument/Instrumentation.java
Mon Aug  7 02:52:06 2006
@@ -0,0 +1,193 @@
+/* Copyright 2006 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package java.lang.instrument;
+
+/**
+ * Instances of this interface may be used by Java instrumentation agent code
+ * for support in carrying out the runtime instrumentation of classes. Using
+ * such an approach, classes may be enhanced with services such as profiling,
+ * logging or tracing which were not included in the source of the original
+ * class.
+ * <p>
+ * A concrete instance of this interface is made available as an input argument
+ * to all Java instrumentation agents'
+ * <code>premain(String agentArgs, Instrumentation inst)</code> method.
+ * </p>
+ * 
+ */
+public interface Instrumentation {
+
+    /**
+     * Registers the supplied <code>transformer</code> argument with the VM.
+     * Any classes that are to be defined or re-defined (if supported) in the VM
+     * will then be offered to the transformer for it to carry out any byte code
+     * modifications. The exception to this scheme is if the class to be defined /
+     * re-defined is a dependency of the transformer.
+     * <p>
+     * This operation can be carried out multiple times on a concrete
+     * <code>Instrumentation</code>. The order of registration is important
+     * as it defines the order in which the transformers' transformation
+     * operation gets called.
+     * <p>
+     * <p>
+     * It is possible for any given instance of
+     * <code>ClassFileTransformer</code> to be registered more than once with
+     * this operation.
+     * 
+     * @param transformer
+     *            a class file transformer
+     * @throws NullPointerException
+     *             if <code>transformer</code> is <code>null</code>.
+     */
+    public void addTransformer(ClassFileTransformer transformer);
+
+    /**
+     * Returns an array of all of the classes that have been loaded into the VM.
+     * 
+     * @return an array of <code>Class</code> objects with each element
+     *         identifying a class that has been loaded into the VM.
+     */
+    public Class[] getAllLoadedClasses();
+
+    /**
+     * Returns an array of all of the classes for which <code>loader</code> is
+     * the <i>initiating</i> class loader.
+     * 
+     * @param loader
+     *            a class loader. In order to obtain the array of classes
+     *            initiated by the bootstrap class loader this argument should
+     *            be <code>null</code>.
+     * @return an array of <code>Class</code> objects with each element
+     *         identifying a class that has been initiated by the specified
+     *         class loader.
+     */
+    public Class[] getInitiatedClasses(ClassLoader loader);
+
+    /**
+     * Returns the number of bytes in memory required by this VM for the
+     * supplied object <code>objectToSize</code>. The returned value should
+     * be taken as an estimation only which is susceptible to change between
+     * separate launches of the VM.
+     * 
+     * @param objectToSize
+     *            any object
+     * @return an approximation of the number of bytes in memory taken up by
+     *         <code>objectToSize</code>.
+     * @throws NullPointerException
+     *             if the given object is null.
+     */
+    public long getObjectSize(Object objectToSize);
+
+    /**
+     * Returns a boolean indication of whether or not this VM supports the
+     * on-the-fly redefining of classes that have been already loaded.
+     * 
+     * @return <code>true</code> if class redefining is supported, otherwise
+     *         <code>false</code>.
+     */
+    public boolean isRedefineClassesSupported();
+
+    /**
+     * Receives an array of {@link ClassDefinition} instances and attempts to
+     * carry out on-the-fly redefining on each of the associated classes.
+     * Redefining in this manner may be used to update the following parts of an
+     * already loaded class:
+     * <ul>
+     * <li>attributes
+     * <li>constant pool
+     * <li>method implementations
+     * </ul>
+     * If any invocations of a redefined method are already active in the VM
+     * when this call is made then they will run to completion and be unaffected
+     * by the outcome of this method. Provided the method redefinition is
+     * successful, all subsequent calls on the method will run the new version.
+     * <br>
+     * Redefining a class may <em>not</em> be used to make changes to any
+     * other aspects of a previously loaded class such as its inheritance
+     * hierarchy, the names or signatures of any of its methods, the names of
+     * any fields, the values of any static variables etc.
+     * <p>
+     * If a class associated with a <code>ClassDefinition</code> is
+     * successfully redefined then there will be no resulting re-run of any of
+     * its initialization code. Similarly, any instances of the class that were
+     * created before the redefining will not be changed in any way. That is,
+     * they will remain in the VM as instances of the previous version of the
+     * class.
+     * </p>
+     * <p>
+     * Note that before the requested redefinitions are attempted, each
+     * {@link ClassFileTransformer} registered with the VM will be given the
+     * opportunity to carry out their own custom transformations of the new
+     * version of the class.
+     * </p>
+     * 
+     * @param definitions
+     *            an array of <code>ClassDefinition</code> objects wrapping
+     *            the details of the classes to be redefined. A zero-length
+     *            array value will not cause an error but, instead, will
+     *            silently do nothing.
+     * @throws ClassNotFoundException
+     *             if any of the classes specified in the contents of
+     *             <code>definitions</code> cannot be located.
+     * @throws UnmodifiableClassException
+     *             if any of the classes specified in the contents of
+     *             <code>definitions</code> cannot be modified.
+     * @throws UnsupportedOperationException
+     *             if this method is not supported in by the VM. May be checked
+     *             in advance by calling {@link #isRedefineClassesSupported()}.
+     * @throws ClassFormatError
+     *             if any of the <code>definitions</code> elements has been
+     *             created with a <code>byte</code> array containing a badly
+     *             formed class file.
+     * @throws NoClassDefFoundError
+     *             if there is disagreement between the name of a class to be
+     *             redefined and the name of the class from the corresponding
+     *             class file format byte array.
+     * @throws UnsupportedClassVersionError
+     *             if the version of any of the classes to be redefined is not
+     *             supported by the VM.
+     * @throws ClassCircularityError
+     *             if a circular dependency is detected among the classes to be
+     *             redefined.
+     * @throws LinkageError
+     *             if a linkage error situation is detected such that there is
+     *             an incompatability between dependent classes.
+     * @throws NullPointerException
+     *             if <code>definitions</code> or any of its elements are
+     *             found to be <code>null</code>.
+     * @see #isRedefineClassesSupported()
+     */
+    public void redefineClasses(ClassDefinition[] definitions)
+            throws ClassNotFoundException, UnmodifiableClassException;
+
+    /**
+     * Removes <i>the most recently added instance of</i> the
+     * <code>ClassFileTransformer</code> object from the VM's list of
+     * registered transformers. After this call completes, the specified
+     * <code>ClassFileTransformer</code> object will no longer have its
+     * <code>transform()<code> method automatically invoked when class definitions
or
+     * redefinitions are attempted. 
+     * 
+     * @param transformer
+     *            a previously registered <code>ClassFileTransformer</code>.
+     * @return <code>true</code> if <code>transformer</code> was
located in
+     *         the list of registered transformers and successfully removed.
+     *         Otherwise, <code>false</code>.
+     * @throws NullPointerException
+     *            if <code>transformer</code> is <code>null</code>.
+     */
+    public boolean removeTransformer(ClassFileTransformer transformer);
+}

Added: incubator/harmony/enhanced/classlib/trunk/modules/instrument/src/main/java/java/lang/instrument/UnmodifiableClassException.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/instrument/src/main/java/java/lang/instrument/UnmodifiableClassException.java?rev=429287&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/instrument/src/main/java/java/lang/instrument/UnmodifiableClassException.java
(added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/instrument/src/main/java/java/lang/instrument/UnmodifiableClassException.java
Mon Aug  7 02:52:06 2006
@@ -0,0 +1,49 @@
+/* Copyright 2006 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package java.lang.instrument;
+
+/**
+ * This exception may be thrown from implementations of the method
+ * {@link java.lang.instrument.Instrumentation#redefineClasses} when one of the
+ * desired class redefinition operations cannot be carried out. Such a situation
+ * may arise if a redefinition attempts to alter the members of a class or its
+ * inheritance hierarchy.
+ * 
+ */
+public class UnmodifiableClassException extends Exception {
+
+    private static final long serialVersionUID = 1716652643585309178L;
+
+    /**
+     * Constructs a new instance of <code>UnmodifiableClassException</code>
+     * with no explanatory message.
+     */
+    public UnmodifiableClassException() {
+        super();
+    }
+
+    /**
+     * Constructs a new instance of <code>UnmodifiableClassException</code>
+     * with the supplied message, <code>s</code>, for explanation.
+     * 
+     * @param s
+     *            a string containing information on why the exception is being
+     *            created.
+     */
+    public UnmodifiableClassException(String s) {
+        super(s);
+    }
+}

Added: incubator/harmony/enhanced/classlib/trunk/modules/instrument/src/test/java/org/apache/harmony/tests/java/lang/instrument/ClassDefinitionTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/instrument/src/test/java/org/apache/harmony/tests/java/lang/instrument/ClassDefinitionTest.java?rev=429287&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/instrument/src/test/java/org/apache/harmony/tests/java/lang/instrument/ClassDefinitionTest.java
(added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/instrument/src/test/java/org/apache/harmony/tests/java/lang/instrument/ClassDefinitionTest.java
Mon Aug  7 02:52:06 2006
@@ -0,0 +1,67 @@
+/* Copyright 2006 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.harmony.tests.java.lang.instrument;
+
+import java.lang.instrument.ClassDefinition;
+
+import junit.framework.TestCase;
+
+public class ClassDefinitionTest extends TestCase {
+
+    /**
+     * @tests java.lang.instrument.ClassDefinition#ClassDefinition(Class<?>, byte[])
+     */
+    public void test_ConstructorLClass$B() {
+        try{
+            new ClassDefinition(null,null);
+            fail("Should throw NullPointerException");
+        } catch (NullPointerException e) {
+            // expected
+        }
+        try{
+            new ClassDefinition(null,new byte[0]);
+            fail("Should throw NullPointerException");
+        } catch (NullPointerException e) {
+            // expected
+        }
+        try{
+            new ClassDefinition(this.getClass(),null);
+            fail("Should throw NullPointerException");
+        } catch (NullPointerException e) {
+            // expected
+        }
+    }
+
+    /**
+     * @tests java.lang.instrument.ClassDefinition#getDefinitionClass()
+     */
+    public void test_getDefinitionClass() {
+        ClassDefinition cd = new ClassDefinition(this.getClass(),new byte[0]);
+        assertSame(this.getClass(),cd.getDefinitionClass());
+    }
+
+    /**
+     * @tests java.lang.instrument.ClassDefinition#getDefinitionClassFile()
+     */
+    public void test_getDefinitionClassFile() {
+        byte[] emptyByteArray = new byte[0];
+        byte[] someByteArray = new byte[1024];
+        ClassDefinition cd = new ClassDefinition(this.getClass(),emptyByteArray);
+        assertSame(emptyByteArray,cd.getDefinitionClassFile());        
+        cd = new ClassDefinition(this.getClass(),someByteArray);
+        assertSame(someByteArray,cd.getDefinitionClassFile());        
+    }
+}



Mime
View raw message