jakarta-bcel-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Habib <hob...@gmail.com>
Subject Re: from BCEL line back to source
Date Sun, 20 Dec 2009 06:59:45 GMT
Obviously, the compiler does some simple optimization to convert a !true to
a false. To detect that an ICONST_0 was a !true in the source code, you can
either turn off that optimization (i don't know if there is a javac option
that does that), or simply inspect the source code to detect a "!true"
string. For that you'll need to inspect the Line Number Table (if the class
has been compiled with the -g option) to get the source code line number for
each ICONST_0 instruction. I don't believe that you can do this only usign
bytecode.

On Sun, Dec 20, 2009 at 3:24 AM, Anton Margoline <margant@gmail.com> wrote:

> Is there a good way to catch assignments to specific value in code?
>
>
> public void testB() {
>  *boolean o = !true;*
> }
>
> translates to
>
> boolean a = !false;
>  public testB() : void
>   L0 (0)
>    *LINENUMBER 32 L0
>    ICONST_0
>    ISTORE 1: o*
>   L1 (3)
>    LINENUMBER 33 L1
>    RETURN
>   L2 (5)
>    LOCALVARIABLE this TestDoubleNegative L0 L2 0
>    LOCALVARIABLE o boolean L1 L2 1
>    MAXSTACK = 1
>    MAXLOCALS = 2
>
> I am particularly interested in getting from ICONST_0 to assignment
> of*!true
> *. Let me know if anyone has an idea how to do this.
> Thanks in Advance!
>

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