[prev in list] [next in list] [prev in thread] [next in thread]
List: bcel-user
Subject: Re: Maintaining Consistancy of JavaClass objects
From: Andrew Huntwork <ash () huntwork ! net>
Date: 2004-04-12 23:25:40
Message-ID: 407B2574.4040008 () huntwork ! net
[Download RAW message or body]
Kevin A. Myers wrote:
[...]
>
> 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)
As you can see here, you're still trying to access the field by its old name. You need to
update all the FieldInstruction's to refer to the field by its new name,
$chx_Orig_BITFoundation. You can either iterate over all Instructions and pick out the
FieldInstructions, or you can play around with the constant pool. see a recent (maybe
last week) thread in this mailing list about the perils of the 2 approaches.
> 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.
I guess this is the same problem, although seeing the actual bytecode would clear this up.
Maybe you compiled this before you edited BITFoundation, and then got the error
afterward? In that case, i strongly suspect it's the same problem.
>
> Kevin M.
> MS in CS @ VT
>
--
"I say to you that the VCR is to the American film
producer and the American public as the Boston
strangler is to the woman home alone."
-Jack Valenti, President, Motion Picture
Association of America, Inc., before
The House Subcommittee on Courts, Civil
Liberties, and The Administration of
Justice, August, 1982,
http://cryptome.org/hrcw-hear.htm
---------------------------------------------------------------------
To unsubscribe, e-mail: bcel-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: bcel-user-help@jakarta.apache.org
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic