Quantcast

Reflect.getIndex() throws ArrayIndexOutOfBoundsException

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Reflect.getIndex() throws ArrayIndexOutOfBoundsException

David Pinheiro
Hi,
I'm running some Genetic Programming (GP) experiments.
GP auto-generates lots of programs to be run by BeanShell.
The majority run correctly, but 1% give ArrayIndexOutOfBoundsException in
Reflect.getIndex() for no apparent reason.
Please run the attached Main.java file.

Same stuff happens with the inputs (just to give some examples):

expression =
"i=0;j=0;temp=0;time=System.currentTimeMillis();for(j=0;j<array.length;j++){if((System.currentTimeMillis()-time)>1000)return
null;if(j<array.length&&i<array.length){temp=array[i];array[i]=array[j];array[j]=temp;}if(j<array.length&&i<array.length){temp=array[i];array[i]=array[j];array[j]=temp;}}for(i=0;i<array.length;i++){if((System.currentTimeMillis()-time)>1000)return
null;if(j<array.length&&i<array.length){temp=array[i];array[i]=array[j];array[j]=temp;}}if(array[i]<array[i]){if(j<array.length&&i<array.length){temp=array[i];array[i]=array[j];array[j]=temp;}}return
array;";
argValues = new int[][] {{7, 3, 2, 9, 5}};

expression =
"i=0;j=0;temp=0;time=System.currentTimeMillis();for(i=0;i<array.length;i++){if((System.currentTimeMillis()-time)>1000)return
null;if(j<array.length&&i<array.length){temp=array[i];array[i]=array[j];array[j]=temp;}}if(array[j]<array[i]){if(j<array.length&&i<array.length){temp=array[i];array[i]=array[j];array[j]=temp;}}for(j=0;j<array.length;j++){if((System.currentTimeMillis()-time)>1000)return
null;if(j<array.length&&i<array.length){temp=array[i];array[i]=array[j];array[j]=temp;}}if(j<array.length&&i<array.length){temp=array[i];array[i]=array[j];array[j]=temp;}if(j<array.length&&i<array.length){temp=array[i];array[i]=array[j];array[j]=temp;}if(j<array.length&&i<array.length){temp=array[i];array[i]=array[j];array[j]=temp;}if(j<array.length&&i<array.length){temp=array[i];array[i]=array[j];array[j]=temp;}if(j<array.length&&i<array.length){temp=array[i];array[i]=array[j];array[j]=temp;}if(j<array.length&&i<array.length){temp=array[i];array[i]=array[j];array[j]=temp;}if(j<array.length&&i<array.length){temp=array[i];array[i]=array[j];array[j]=temp;}if(j<array.length&&i<array.length){temp=array[i];array[i]=array[j];array[j]=temp;}if(array[j]<array[j]){if(j<array.length&&i<array.length){temp=array[i];array[i]=array[j];array[j]=temp;}if(j<array.length&&i<array.length){temp=array[i];array[i]=array[j];array[j]=temp;}if(j<array.length&&i<array.length){temp=array[i];array[i]=array[j];array[j]=temp;}if(j<array.length&&i<array.length){temp=array[i];array[i]=array[j];array[j]=temp;}}return
array;";
argValues = new int[][] {{5, 7, 3, 2, 9}};

expression =
"i=0;j=0;temp=0;time=System.currentTimeMillis();for(j=0;j<array.length;j++){if((System.currentTimeMillis()-time)>1000)return
null;if(j<array.length&&i<array.length){temp=array[i];array[i]=array[j];array[j]=temp;}if(j<array.length&&i<array.length){temp=array[i];array[i]=array[j];array[j]=temp;}if(j<array.length&&i<array.length){temp=array[i];array[i]=array[j];array[j]=temp;}if(j<array.length&&i<array.length){temp=array[i];array[i]=array[j];array[j]=temp;}if(j<array.length&&i<array.length){temp=array[i];array[i]=array[j];array[j]=temp;}if(j<array.length&&i<array.length){temp=array[i];array[i]=array[j];array[j]=temp;}if(j<array.length&&i<array.length){temp=array[i];array[i]=array[j];array[j]=temp;}if(j<array.length&&i<array.length){temp=array[i];array[i]=array[j];array[j]=temp;}if(j<array.length&&i<array.length){temp=array[i];array[i]=array[j];array[j]=temp;}if(j<array.length&&i<array.length){temp=array[i];array[i]=array[j];array[j]=temp;}if(j<array.length&&i<array.length){temp=array[i];array[i]=array[j];array[j]=temp;}}if(array[j]<array[j]){if(array[j]<array[i]){if(j<array.length&&i<array.length){temp=array[i];array[i]=array[j];array[j]=temp;}if(j<array.length&&i<array.length){temp=array[i];array[i]=array[j];array[j]=temp;}}}return
array;";
argValues = new int[][] {{5, 7, 3, 2, 9}};

I've tried this with bsh-2.0b5, bsh-2.0b4 and bsh-1.3.0 allways giving the
same ArrayIndexOutOfBoundsException.
If anyone can help, I'll appreciate a lot.
Best regards,
David

------------------------------------------------------------------------------
Download BIRT iHub F-Type - The Free Enterprise-Grade BIRT Server
from Actuate! Instantly Supercharge Your Business Reports and Dashboards
with Interactivity, Sharing, Native Excel Exports, App Integration & more
Get technology previously reserved for billion-dollar corporations, FREE
http://pubads.g.doubleclick.net/gampad/clk?id=164703151&iu=/4140/ostg.clktrk
_______________________________________________
Beanshell-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/beanshell-users
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Reflect.getIndex() throws ArrayIndexOutOfBoundsException

David Pinheiro
It seems that the java file was withdrawn. It's contents are:


package testesBeanShell;

import bsh.EvalError;

public class Main {

    private final bsh.Interpreter beanShell = new bsh.Interpreter();;

    public static void main (String[] args){
        Main main = new Main();
        main.eval();
    }

    public void eval(){

        String expression =
"i=0;j=0;temp=0;time=System.currentTimeMillis();for(i=0;i<array.length;i++){if((System.currentTimeMillis()-time)>1000)return
null;for(j=0;j<array.length;j++){if((System.currentTimeMillis()-time)>1000)return
null;if(j<array.length&&i<array.length){temp=array[i];array[i]=array[j];array[j]=temp;}}if(j<array.length&&i<array.length){temp=array[i];array[i]=array[j];array[j]=temp;}}if(array[j]<array[j]){if(array[i]<array[j]){if(j<array.length&&i<array.length){temp=array[i];array[i]=array[j];array[j]=temp;}}}return
array;";
        String[] argNames = new String[] {"array"};
        Object[] argValues = new int[][] {{2, 9, 5, 7, 3}};

        Object result = null;
        if (expression != null) {
            try {
                // Declare all the variables.
                for (int i = 0; i < argNames.length; i++) {
                    beanShell.set(argNames[i], argValues[i]);
                }

                result = beanShell.eval(expression);

            } catch (final EvalError e) {
                e.printStackTrace();
            }
        }
        System.out.println((String)result);
    }
}



Thanks!
Best regards,
David


2014-12-18 0:44 GMT+00:00 David Pinheiro <[hidden email]>:

>
> Hi,
> I'm running some Genetic Programming (GP) experiments.
> GP auto-generates lots of programs to be run by BeanShell.
> The majority run correctly, but 1% give ArrayIndexOutOfBoundsException in
> Reflect.getIndex() for no apparent reason.
> Please run the attached Main.java file.
>
> Same stuff happens with the inputs (just to give some examples):
>
> expression =
> "i=0;j=0;temp=0;time=System.currentTimeMillis();for(j=0;j<array.length;j++){if((System.currentTimeMillis()-time)>1000)return
> null;if(j<array.length&&i<array.length){temp=array[i];array[i]=array[j];array[j]=temp;}if(j<array.length&&i<array.length){temp=array[i];array[i]=array[j];array[j]=temp;}}for(i=0;i<array.length;i++){if((System.currentTimeMillis()-time)>1000)return
> null;if(j<array.length&&i<array.length){temp=array[i];array[i]=array[j];array[j]=temp;}}if(array[i]<array[i]){if(j<array.length&&i<array.length){temp=array[i];array[i]=array[j];array[j]=temp;}}return
> array;";
> argValues = new int[][] {{7, 3, 2, 9, 5}};
>
> expression =
> "i=0;j=0;temp=0;time=System.currentTimeMillis();for(i=0;i<array.length;i++){if((System.currentTimeMillis()-time)>1000)return
> null;if(j<array.length&&i<array.length){temp=array[i];array[i]=array[j];array[j]=temp;}}if(array[j]<array[i]){if(j<array.length&&i<array.length){temp=array[i];array[i]=array[j];array[j]=temp;}}for(j=0;j<array.length;j++){if((System.currentTimeMillis()-time)>1000)return
> null;if(j<array.length&&i<array.length){temp=array[i];array[i]=array[j];array[j]=temp;}}if(j<array.length&&i<array.length){temp=array[i];array[i]=array[j];array[j]=temp;}if(j<array.length&&i<array.length){temp=array[i];array[i]=array[j];array[j]=temp;}if(j<array.length&&i<array.length){temp=array[i];array[i]=array[j];array[j]=temp;}if(j<array.length&&i<array.length){temp=array[i];array[i]=array[j];array[j]=temp;}if(j<array.length&&i<array.length){temp=array[i];array[i]=array[j];array[j]=temp;}if(j<array.length&&i<array.length){temp=array[i];array[i]=array[j];array[j]=temp;}if(j<array.length&&i<array.length){temp=array[i];array[i]=array[j];array[j]=temp;}if(j<array.length&&i<array.length){temp=array[i];array[i]=array[j];array[j]=temp;}if(array[j]<array[j]){if(j<array.length&&i<array.length){temp=array[i];array[i]=array[j];array[j]=temp;}if(j<array.length&&i<array.length){temp=array[i];array[i]=array[j];array[j]=temp;}if(j<array.length&&i<array.length){temp=array[i];array[i]=array[j];array[j]=temp;}if(j<array.length&&i<array.length){temp=array[i];array[i]=array[j];array[j]=temp;}}return
> array;";
> argValues = new int[][] {{5, 7, 3, 2, 9}};
>
> expression =
> "i=0;j=0;temp=0;time=System.currentTimeMillis();for(j=0;j<array.length;j++){if((System.currentTimeMillis()-time)>1000)return
> null;if(j<array.length&&i<array.length){temp=array[i];array[i]=array[j];array[j]=temp;}if(j<array.length&&i<array.length){temp=array[i];array[i]=array[j];array[j]=temp;}if(j<array.length&&i<array.length){temp=array[i];array[i]=array[j];array[j]=temp;}if(j<array.length&&i<array.length){temp=array[i];array[i]=array[j];array[j]=temp;}if(j<array.length&&i<array.length){temp=array[i];array[i]=array[j];array[j]=temp;}if(j<array.length&&i<array.length){temp=array[i];array[i]=array[j];array[j]=temp;}if(j<array.length&&i<array.length){temp=array[i];array[i]=array[j];array[j]=temp;}if(j<array.length&&i<array.length){temp=array[i];array[i]=array[j];array[j]=temp;}if(j<array.length&&i<array.length){temp=array[i];array[i]=array[j];array[j]=temp;}if(j<array.length&&i<array.length){temp=array[i];array[i]=array[j];array[j]=temp;}if(j<array.length&&i<array.length){temp=array[i];array[i]=array[j];array[j]=temp;}}if(array[j]<array[j]){if(array[j]<array[i]){if(j<array.length&&i<array.length){temp=array[i];array[i]=array[j];array[j]=temp;}if(j<array.length&&i<array.length){temp=array[i];array[i]=array[j];array[j]=temp;}}}return
> array;";
> argValues = new int[][] {{5, 7, 3, 2, 9}};
>
> I've tried this with bsh-2.0b5, bsh-2.0b4 and bsh-1.3.0 allways giving the
> same ArrayIndexOutOfBoundsException.
> If anyone can help, I'll appreciate a lot.
> Best regards,
> David
>
------------------------------------------------------------------------------
Download BIRT iHub F-Type - The Free Enterprise-Grade BIRT Server
from Actuate! Instantly Supercharge Your Business Reports and Dashboards
with Interactivity, Sharing, Native Excel Exports, App Integration & more
Get technology previously reserved for billion-dollar corporations, FREE
http://pubads.g.doubleclick.net/gampad/clk?id=164703151&iu=/4140/ostg.clktrk
_______________________________________________
Beanshell-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/beanshell-users
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Reflect.getIndex() throws ArrayIndexOutOfBoundsException

David Pinheiro
Sorry, It was my mistake.

Alter the for() the index is array.length, so if i use it in array[index]
it is out of bounds.

Sorry to bother.
David


2014-12-18 9:40 GMT+00:00 David Pinheiro <[hidden email]>:

>
> It seems that the java file was withdrawn. It's contents are:
>
>
> package testesBeanShell;
>
> import bsh.EvalError;
>
> public class Main {
>
>     private final bsh.Interpreter beanShell = new bsh.Interpreter();;
>
>     public static void main (String[] args){
>         Main main = new Main();
>         main.eval();
>     }
>
>     public void eval(){
>
>         String expression =
> "i=0;j=0;temp=0;time=System.currentTimeMillis();for(i=0;i<array.length;i++){if((System.currentTimeMillis()-time)>1000)return
> null;for(j=0;j<array.length;j++){if((System.currentTimeMillis()-time)>1000)return
> null;if(j<array.length&&i<array.length){temp=array[i];array[i]=array[j];array[j]=temp;}}if(j<array.length&&i<array.length){temp=array[i];array[i]=array[j];array[j]=temp;}}if(array[j]<array[j]){if(array[i]<array[j]){if(j<array.length&&i<array.length){temp=array[i];array[i]=array[j];array[j]=temp;}}}return
> array;";
>         String[] argNames = new String[] {"array"};
>         Object[] argValues = new int[][] {{2, 9, 5, 7, 3}};
>
>         Object result = null;
>         if (expression != null) {
>             try {
>                 // Declare all the variables.
>                 for (int i = 0; i < argNames.length; i++) {
>                     beanShell.set(argNames[i], argValues[i]);
>                 }
>
>                 result = beanShell.eval(expression);
>
>             } catch (final EvalError e) {
>                 e.printStackTrace();
>             }
>         }
>         System.out.println((String)result);
>     }
> }
>
>
>
> Thanks!
> Best regards,
> David
>
>
> 2014-12-18 0:44 GMT+00:00 David Pinheiro <[hidden email]>:
>>
>> Hi,
>> I'm running some Genetic Programming (GP) experiments.
>> GP auto-generates lots of programs to be run by BeanShell.
>> The majority run correctly, but 1% give ArrayIndexOutOfBoundsException in
>> Reflect.getIndex() for no apparent reason.
>> Please run the attached Main.java file.
>>
>> Same stuff happens with the inputs (just to give some examples):
>>
>> expression =
>> "i=0;j=0;temp=0;time=System.currentTimeMillis();for(j=0;j<array.length;j++){if((System.currentTimeMillis()-time)>1000)return
>> null;if(j<array.length&&i<array.length){temp=array[i];array[i]=array[j];array[j]=temp;}if(j<array.length&&i<array.length){temp=array[i];array[i]=array[j];array[j]=temp;}}for(i=0;i<array.length;i++){if((System.currentTimeMillis()-time)>1000)return
>> null;if(j<array.length&&i<array.length){temp=array[i];array[i]=array[j];array[j]=temp;}}if(array[i]<array[i]){if(j<array.length&&i<array.length){temp=array[i];array[i]=array[j];array[j]=temp;}}return
>> array;";
>> argValues = new int[][] {{7, 3, 2, 9, 5}};
>>
>> expression =
>> "i=0;j=0;temp=0;time=System.currentTimeMillis();for(i=0;i<array.length;i++){if((System.currentTimeMillis()-time)>1000)return
>> null;if(j<array.length&&i<array.length){temp=array[i];array[i]=array[j];array[j]=temp;}}if(array[j]<array[i]){if(j<array.length&&i<array.length){temp=array[i];array[i]=array[j];array[j]=temp;}}for(j=0;j<array.length;j++){if((System.currentTimeMillis()-time)>1000)return
>> null;if(j<array.length&&i<array.length){temp=array[i];array[i]=array[j];array[j]=temp;}}if(j<array.length&&i<array.length){temp=array[i];array[i]=array[j];array[j]=temp;}if(j<array.length&&i<array.length){temp=array[i];array[i]=array[j];array[j]=temp;}if(j<array.length&&i<array.length){temp=array[i];array[i]=array[j];array[j]=temp;}if(j<array.length&&i<array.length){temp=array[i];array[i]=array[j];array[j]=temp;}if(j<array.length&&i<array.length){temp=array[i];array[i]=array[j];array[j]=temp;}if(j<array.length&&i<array.length){temp=array[i];array[i]=array[j];array[j]=temp;}if(j<array.length&&i<array.length){temp=array[i];array[i]=array[j];array[j]=temp;}if(j<array.length&&i<array.length){temp=array[i];array[i]=array[j];array[j]=temp;}if(array[j]<array[j]){if(j<array.length&&i<array.length){temp=array[i];array[i]=array[j];array[j]=temp;}if(j<array.length&&i<array.length){temp=array[i];array[i]=array[j];array[j]=temp;}if(j<array.length&&i<array.length){temp=array[i];array[i]=array[j];array[j]=temp;}if(j<array.length&&i<array.length){temp=array[i];array[i]=array[j];array[j]=temp;}}return
>> array;";
>> argValues = new int[][] {{5, 7, 3, 2, 9}};
>>
>> expression =
>> "i=0;j=0;temp=0;time=System.currentTimeMillis();for(j=0;j<array.length;j++){if((System.currentTimeMillis()-time)>1000)return
>> null;if(j<array.length&&i<array.length){temp=array[i];array[i]=array[j];array[j]=temp;}if(j<array.length&&i<array.length){temp=array[i];array[i]=array[j];array[j]=temp;}if(j<array.length&&i<array.length){temp=array[i];array[i]=array[j];array[j]=temp;}if(j<array.length&&i<array.length){temp=array[i];array[i]=array[j];array[j]=temp;}if(j<array.length&&i<array.length){temp=array[i];array[i]=array[j];array[j]=temp;}if(j<array.length&&i<array.length){temp=array[i];array[i]=array[j];array[j]=temp;}if(j<array.length&&i<array.length){temp=array[i];array[i]=array[j];array[j]=temp;}if(j<array.length&&i<array.length){temp=array[i];array[i]=array[j];array[j]=temp;}if(j<array.length&&i<array.length){temp=array[i];array[i]=array[j];array[j]=temp;}if(j<array.length&&i<array.length){temp=array[i];array[i]=array[j];array[j]=temp;}if(j<array.length&&i<array.length){temp=array[i];array[i]=array[j];array[j]=temp;}}if(array[j]<array[j]){if(array[j]<array[i]){if(j<array.length&&i<array.length){temp=array[i];array[i]=array[j];array[j]=temp;}if(j<array.length&&i<array.length){temp=array[i];array[i]=array[j];array[j]=temp;}}}return
>> array;";
>> argValues = new int[][] {{5, 7, 3, 2, 9}};
>>
>> I've tried this with bsh-2.0b5, bsh-2.0b4 and bsh-1.3.0 allways giving
>> the same ArrayIndexOutOfBoundsException.
>> If anyone can help, I'll appreciate a lot.
>> Best regards,
>> David
>>
>
------------------------------------------------------------------------------
Download BIRT iHub F-Type - The Free Enterprise-Grade BIRT Server
from Actuate! Instantly Supercharge Your Business Reports and Dashboards
with Interactivity, Sharing, Native Excel Exports, App Integration & more
Get technology previously reserved for billion-dollar corporations, FREE
http://pubads.g.doubleclick.net/gampad/clk?id=164703151&iu=/4140/ostg.clktrk
_______________________________________________
Beanshell-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/beanshell-users
Loading...