ZhiqiangGao / beanshell2

Automatically exported from code.google.com/p/beanshell2
0 stars 0 forks source link

Reflect.getIndex() throws ArrayIndexOutOfBoundsException #106

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1.Run the Main.java file attached

What is the expected output? An array
What do you see instead? ArrayIndexOutOfBoundsException

What version of the product are you using? bsh-2.1.8
On what operating system? Windows XP + Java 1.7.71

Please provide any additional information below.

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];a
rray[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];a
rray[i]=array[j];array[j]=temp;}}for(j=0;j<array.length;j++){if((System.currentT
imeMillis()-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];arr
ay[j]=temp;}if(j<array.length&&i<array.length){temp=array[i];array[i]=array[j];a
rray[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]=arra
y[j];array[j]=temp;}if(j<array.length&&i<array.length){temp=array[i];array[i]=ar
ray[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.lengt
h){temp=array[i];array[i]=array[j];array[j]=temp;}if(j<array.length&&i<array.len
gth){temp=array[i];array[i]=array[j];array[j]=temp;}if(j<array.length&&i<array.l
ength){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];arra
y[j]=temp;}if(j<array.length&&i<array.length){temp=array[i];array[i]=array[j];ar
ray[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]=arr
ay[j];array[j]=temp;}if(j<array.length&&i<array.length){temp=array[i];array[i]=a
rray[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<arr
ay.length&&i<array.length){temp=array[i];array[i]=array[j];array[j]=temp;}if(j<a
rray.length&&i<array.length){temp=array[i];array[i]=array[j];array[j]=temp;}}}re
turn array;";
argValues = new int[][] {{5, 7, 3, 2, 9}};

I've tried this with bsh-2.1.8, 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

Original issue reported on code.google.com by davidp...@gmail.com on 18 Dec 2014 at 12:46

Attachments:

GoogleCodeExporter commented 9 years ago
Sorry, It was my mistake.

Alter the for(int i=0;i<array.length;i++) the i is array.length, so if i use it 
in array[i] it is out of bounds.

Sorry to bother.
Thanks,
David

Original comment by davidp...@gmail.com on 18 Dec 2014 at 9:57

GoogleCodeExporter commented 9 years ago

Original comment by pejob...@gmail.com on 19 Dec 2014 at 11:00