1

How do I in BCEL check for this..

Say the bytecode in java is

newarray 10 (int)

I got this already done for visitor

instruction instanceof NEWARRAY

public boolean visit(Instruction instr) {
    return instr instanceof NEWARRAY;
}

But I also have to check if the newarray is int[]

how do I check this in BCEL?

I tried this

 && ((NEWARRAY) instr).getType() == Type.INT;

to well

return instr instanceof NEWARRAY && ((NEWARRAY) instr).getType() == Type.INT;

But you can see the above ^ will not work as it will never be int.. but int[]

But Type.INT is just int.. and not int[]..

How I represent Type int[]?

I was reading the BCEL source code and NEWARRAY.getType() returns this..

     /**
      * @return type of constructed array
      */
     public final Type getType() {
         return new ArrayType(BasicType.getType(type), 1);
     }

As you can see it returns a Type class so.. looking at http://commons.apache.org/bcel/apidocs/org/apache/bcel/generic/Type.html

http://commons.apache.org/bcel/apidocs/org/apache/bcel/generic/ArrayType.html

there isn't any Type's for ARRAY int[].

SSpoke
  • 5,656
  • 10
  • 72
  • 124

1 Answers1

1

I don't think I understand your question well, but what about this:

if(instr.getClass().isArray()) return instr instanceof NEWARRAY[];
else return instr instanceof NEWARRAY;
Eng.Fouad
  • 115,165
  • 71
  • 313
  • 417
  • well NEWARRAY is a bytecode instruction.. in java asm I doubt NEWARRAY[] exists lol. – SSpoke Aug 16 '11 at 07:16
  • I'm trying to understand why `((NEWARRAY) instr).getType() == Type.INT` doesn't work.. well `getTypecode()` gives me `10`.. – SSpoke Aug 16 '11 at 07:22