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);
 
            tempClass.setClassName(newName);
            tempClass.addInterface(originalName);
 
            if
(sourceClass.getSuperclassName().equals("java.lang.Object"))
 
sourceClass.setSuperclassName("org.jmlspecs.racwrap.bit.Wrapped");
 
            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
$chx_Statics_BITFoundation.newObject($chx_Statics_BITFoundation.java:9)
            at RunTests.testFoundation(RunTests.java:52)
 
 
-----START $chx_Orig_BITFoundation Post byte code editing---
public class $chx_Orig_BITFoundation extends
org.jmlspecs.racwrap.bit.Wrapped
implements                   BITFoundation
filename                        BITFoundation.java
compiled from                BITFoundation.java
compiler version 46.0
access flags                  33
constant pool                 25 entries
ACC_SUPER flag                      true
 
Attribute(s):
            SourceFile(BITFoundation.java)
 
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
putfield/putstatic
            at
$chx_Statics_BITFoundation.newObject($chx_Statics_BITFoundation.java:15)
            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_Orig_BITFoundation();
            } //$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

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