jakarta-bcel-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Kevin A. Myers" <kemye...@vt.edu>
Subject Maintaining Consistancy of JavaClass objects
Date Mon, 12 Apr 2004 22:10:23 GMT
Greetings all,
I am relatively inexperienced with BCEL. I am using it to implement a
custom class loader that dynamically wraps classes so that compiled
run-time assertion checks can be turned on or off at run-time; while
leaving the original class file unmodified without the assertion checks.
This (hopefully) will be part of the JML
<http://www.cs.iastate.edu/~leavens/JML/>  distribution. 
During this process, we have to rename certain class files and then mark
them as implementing an interface that matches their previous name, and
extend all base classes from 'org.jmlspecs.racwrap.bit.Wrapped'.  Below
is the (approximate) code I am attempting these three changes with.
private JavaClass makeWrappedClass(JavaClass sourceClass) {
            ClassGen tempClass = new ClassGen(sourceClass);
            String originalName = tempClass.getClassName();
            String newName = JavaClassTree.getPackage(originalName) +
"$chx_Orig_" + JavaClassTree.getClassName(originalName);
            return tempClass.getJavaClass();
} //makeWrappedClass()
However I am running into two errors from the resulting class.
First: The modified class cannot access any of its internal fields, as
they seem to be disappearing. Below is a reduced stack trace and the
display of the resulting class. (Note we are using our own class loader,
repository, and a modified classpath, and with the altered name - I have
been unsuccessful in sending the modified class to JustIce.)
1) testFoundation(RunTests)java.lang.NoSuchFieldError: anyField
            at $chx_Orig_BITFoundation.<init>(BITFoundation.java:8)
            at RunTests.testFoundation(RunTests.java:52)
-----START $chx_Orig_BITFoundation Post byte code editing---
public class $chx_Orig_BITFoundation extends
implements                   BITFoundation
filename                        BITFoundation.java
compiled from                BITFoundation.java
compiler version 46.0
access flags                  33
constant pool                 25 entries
ACC_SUPER flag                      true
1 fields:
            boolean anyField
3 methods:
            public void <init>()
            public boolean isWrapped()
            public boolean accessAnyField()
public void <init>()
Code(max_stack = 2, max_locals = 1, code_length = 10)
0:    aload_0
1:    invokespecial          java.lang.Object.<init> ()V (1)
4:    aload_0
5:    iconst_1
6:    putfield                   BITFoundation.anyField Z (2)
9:    return
Attribute(s) = 
LocalVariable(start_pc = 0, length = 10, index = 0:BITFoundation this)
LineNumber(0, 3), LineNumber(4, 8)
-----END-- $chx_Orig_BITFoundation Post byte code editing---
Second: When all field access' are removed.. I receive the following
error when executing the following code, which has not been altered (at
all) by BCEL.
1) testFoundation(RunTests)java.lang.VerifyError: (class:
$chx_Wrap_BITFoundation, method: <init> signature: ()V) Bad type in
            at RunTests.testFoundation(RunTests.java:52)
            public static BITFoundation newObject() {
                        $chx_Wrap_BITFoundation result = new
$chx_Wrap_BITFoundation(); <--------- *here*
                        result.access = access;
                        return (BITFoundation) result;
            } //newObject()
            --with--  //$chx_Wrap_BITFoundation constructor
            public $chx_Wrap_BITFoundation() {
                        _wrapped_object = (Wrapped) new
            } //$chx_Wrap_BITFoundation()
Is my BCEL code not committing the changes properly? Have I left the
class in an inconsistent state? Any help would be appreciated.
Kevin M.
MS in CS @ VT

  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message