[ 
https://issues.apache.org/jira/browse/BCEL-289?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16013696#comment-16013696
 ] 

Pietro Ferrara commented on BCEL-289:
-------------------------------------

As far as I can understand (I'm debugging with the code of release 6.0), it 
seems that there is a problem with the syntetic parameter of the inner 
constructor: at bytecode level, the signature of the constructor is:
{code:java}
public void <init>(Test arg0, Object arg1, Object arg2) 
{code}

The code raising the exception is the first line of the following for loop:

{code:java}
for (int j = 0; j < arg_types.length; j++) {
  // This returns Annotation[] ...
  final ParameterAnnotationEntry immutableArray = rpa
  .getParameterAnnotationEntries()[j];
  // ... which needs transforming into an AnnotationGen[] ...
  final List<AnnotationEntryGen> mutable = 
makeMutableVersion(immutableArray.getAnnotationEntries());
  // ... then add these to any we already know about
  param_annotations[j].addAll(mutable);
 }
{code}

When I debug class MethodGen just before the exception is raisen, I see that:
- arg_types is:
{noformat}
[Test, java.lang.Object, java.lang.Object]
{noformat}
- rpa.parameter_annotation_table (returned by getParameterAnnotationEntries) is:
{noformat}
[@LA;, @LB;]
{noformat}

It looks like when rpa (RuntimeVisibleParameterAnnotations) is built it does 
not take into account the syntectic parameter.

rpa comes from the field attribute_vect. If you don't have any annotation on 
parameters, I expect attribute_vect to be an empty collection, so the body of 
the for loop wrapping the code crashing is never executed.

Hope this helps!

> Crash when parsing constructor of inner classes with parameters annotated
> -------------------------------------------------------------------------
>
>                 Key: BCEL-289
>                 URL: https://issues.apache.org/jira/browse/BCEL-289
>             Project: Commons BCEL
>          Issue Type: Bug
>          Components: Parser
>    Affects Versions: 6.0
>            Reporter: Pietro Ferrara
>            Priority: Critical
>             Fix For: 6.1
>
>
> BCEL crashes when parsing the constructor of an inner class whose parameters 
> are annotated. For instance, when parsing the jar obtained from the following 
> classes:
> {code:java}
> public @interface A {}
> public @interface B {}
> public class Test {
>     public class Inner {
>       public Inner(@A Object a, @B Object b) {}
>     }
> }
> {code}
> In particular:
> {code:java}
>               ClassParser cp = new ClassParser(args[0]);
>               ClassGen cg = new ClassGen(cp.parse());
>               MethodGen mg = new MethodGen(cg.getMethodAt(0), 
> cg.getClassName(), cg.getConstantPool());
>               mg.getAnnotationsOnParameter(0);
> {code}
> (where args\[0\] points to Test$Inner.class)
> you get
> {noformat}
> Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 2
>       at 
> org.apache.bcel.generic.MethodGen.ensureExistingParameterAnnotationsUnpacked(MethodGen.java:1120)
>       at 
> org.apache.bcel.generic.MethodGen.getAnnotationsOnParameter(MethodGen.java:1073)
> {noformat}



--
This message was sent by Atlassian JIRA
(v6.3.15#6346)

Reply via email to