[Soot-list] Bad use of primitive type when performing transformations needed

Zeinab Lashkaripour lashkaripour at yahoo.com
Sat Jun 8 18:56:16 EDT 2013


Hi again,

I would be grateful if any one could guide me in the following:

Consider the code below:

    String a = "value";
    List info = new ArrayList();    
    info.add(4 + a.length());

The equivalentJimple is:
   java.lang.String a;
   java.util.ArrayList info, $r0;
   int i, $i0, $i1;
   java.lang.Integer $r1;        
        .......
  

    $i0 = virtualinvoke a.<java.lang.String: int length()>();
    $i1 = 4 + $i0;
    $r1 = staticinvoke <java.lang.Integer: java.lang.Integer valueOf(int)>($i1);
    interfaceinvoke info.<java.util.List: boolean add(java.lang.Object)>($r1);

I used the same  way in creating my jimple in order to get the equivalent code that I want (in this example: info.add(4 + a.length());) but, I get the exception in [1] where 'j' (a local with RefType.v("int")) has the same role as $i0.

I do not know the cause of this exception since 'j' is of type int and the return type of length() is also int (at the end I have used the valueOf(int) so that an Integer is added to the list). 
It should be mentioned that where ever needed I have used the instance of Integer as Bernhard suggestedin the previous mail (thanks again).

Regards,
Zeinab


[1]
Exception in thread "main" java.lang.RuntimeException: Warning: Bad use of primitive type at j = virtualinvoke a.<java.lang.String: int length()>() in <....> in <........>


________________________________
 From: Bernhard Berger <berber at tzi.de>
To: Zeinab Lashkaripour <lashkaripour at yahoo.com> 
Cc: "soot-list at sable.mcgill.ca" <soot-list at sable.mcgill.ca> 
Sent: Saturday, June 8, 2013 8:02 PM
Subject: Re: [Soot-list] Bad use of primitive type when performing transformations needed
 


Hi Zeinab,

you have to do the auto boxing magic that is done by the compiler. You have to create a new instance of Integer and call the constructor with your int constant. The instance can be added to the list.

Regards,
Bernhard

Am 08.06.2013 um 17:01 schrieb Zeinab Lashkaripour <lashkaripour at yahoo.com>:

Hi every one,
>
>
>I need to perform the following transformation:
>Add a constant value to an ArrayList. If the list is named info and I want to add a constant 14, then I need to add the following to the code:
>    info.add(14)
>
>
>I used a newVirtualInvokeExpr for this and a IntConstant.v(14) for the parameter and I got the exception [1]. Because int is a primitive and not an object I thought that the exception might be related to the fact that I used a IntConstant as parameter therefore, I added a new Integer local and assigned it to IntConstant.v(14) then used the local as the parameter of the method and got the exception in [2]. I know that the second way I tried is somehow the same as the first one but, I don't know another way to use so that the exception will not appear.
>
>
>Could any one help me in this issue?
>
>
>Regards,
>Zeinab
>
>
>
>[1]
>
>Exception in thread "main" java.lang.RuntimeException: Warning: Bad use of primitive type in argument 0 of call at virtualinvoke info.<java.util.ArrayList: boolean add(java.lang.Object)>(14) in <.....> in <...................>
>    at soot.Body.checkCopy(Body.java:645)
>    at soot.Body.checkTypes(Body.java:632)
>    at soot.Body.validate(Body.java:236)
>    at soot.jimple.JimpleBody.validate(JimpleBody.java:66)
>    at soot.PackManager.runBodyPacks(PackManager.java:777)
>    at soot.PackManager.runBodyPacks(PackManager.java:463)
>    at
 soot.PackManager.runBodyPacks(PackManager.java:380)
>    at soot.PackManager.runPacks(PackManager.java:357)
>    at soot.Main.run(Main.java:198)
>    at soot.Main.main(Main.java:141)
>    at MyMain.main(MyMain.java:77)
>
>
>
>[2]
>
>Exception in thread "main" java.lang.RuntimeException: Warning: Bad use of primitive type at k = 14 in <.....> in <...................>
>    at
 soot.Body.checkCopy(Body.java:645)
>    at soot.Body.checkTypes(Body.java:610)
>    at soot.Body.validate(Body.java:236)
>    at soot.jimple.JimpleBody.validate(JimpleBody.java:66)
>    at soot.PackManager.runBodyPacks(PackManager.java:777)
>    at soot.PackManager.runBodyPacks(PackManager.java:463)
>    at soot.PackManager.runBodyPacks(PackManager.java:380)
>    at soot.PackManager.runPacks(PackManager.java:357)
>    at soot.Main.run(Main.java:198)
>    at soot.Main.main(Main.java:141)
>    at MyMain.main(MyMain.java:77)_______________________________________________
>Soot-list mailing list
>Soot-list at sable.mcgill.ca
>http://mailman.cs.mcgill.ca/mailman/listinfo/soot-list
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.cs.mcgill.ca/pipermail/soot-list/attachments/20130608/13d379c2/attachment.html 


More information about the Soot-list mailing list