@@ -1581,20 +1581,35 @@ private void readMethods() throws IOException, ClassfileFormatException {
15811581 public void decorate (final MethodTypeSignature methodTypeSignature ) {
15821582 if (targetType == 0x01 ) {
15831583 // Type parameter declaration of generic method or constructor
1584- methodTypeSignature .getTypeParameters ().get (typeParameterIndex )
1585- .addTypeAnnotation (typePath , annotationInfo );
1586- } else if (targetType == 0x12 ) {
1587- // Type in bound of type parameter declaration of generic method or constructor
1588- final TypeParameter typeParameter = methodTypeSignature
1589- .getTypeParameters ().get (typeParameterIndex );
1590- // TODO: documentation does not specify if bound index should be treated this way *******************
1591- if (boundIndex == 0 ) {
1592- typeParameter .getClassBound ().addTypeAnnotation (typePath ,
1584+ final List <TypeParameter > typeParameters = methodTypeSignature
1585+ .getTypeParameters ();
1586+ if (typeParameters != null
1587+ && typeParameterIndex < typeParameters .size ()) {
1588+ typeParameters .get (typeParameterIndex ).addTypeAnnotation (typePath ,
15931589 annotationInfo );
1594- } else {
1595- typeParameter .getInterfaceBounds ().get (boundIndex - 1 )
1596- .addTypeAnnotation (typePath , annotationInfo );
15971590 }
1591+ // else this is a method type descriptor, not a method type signature,
1592+ // so there are no type parameters
1593+ } else if (targetType == 0x12 ) {
1594+ // Type in bound of type parameter declaration of generic method or
1595+ // constructor
1596+ final List <TypeParameter > typeParameters = methodTypeSignature
1597+ .getTypeParameters ();
1598+ if (typeParameters != null
1599+ && typeParameterIndex < typeParameters .size ()) {
1600+ final TypeParameter typeParameter = typeParameters
1601+ .get (typeParameterIndex );
1602+ // boundIndex == 0 => class bound; boundIndex > 0 => interface bound
1603+ if (boundIndex == 0 ) {
1604+ typeParameter .getClassBound ().addTypeAnnotation (typePath ,
1605+ annotationInfo );
1606+ } else {
1607+ typeParameter .getInterfaceBounds ().get (boundIndex - 1 )
1608+ .addTypeAnnotation (typePath , annotationInfo );
1609+ }
1610+ }
1611+ // else this is a method type descriptor, not a method type signature,
1612+ // so there are no type parameters
15981613 } else if (targetType == 0x14 ) {
15991614 // Return type of method, or type of newly constructed object
16001615 methodTypeSignature .getResultType ().addTypeAnnotation (typePath ,
@@ -1603,14 +1618,13 @@ public void decorate(final MethodTypeSignature methodTypeSignature) {
16031618 // Receiver type of method or constructor (explicit receiver parameter)
16041619 final List <TypeSignature > paramTypeSignatures = methodTypeSignature
16051620 .getParameterTypeSignatures ();
1606- if (paramTypeSignatures .size () == 0 ) {
1607- throw new IllegalArgumentException (
1608- "No explicit receiver parameter" );
1621+ if (paramTypeSignatures != null && paramTypeSignatures .size () > 0 ) {
1622+ // TODO: is this the right way to apply a receiver type annotation? **************************
1623+ final TypeSignature receiverParamTypeSignature = paramTypeSignatures
1624+ .get (0 );
1625+ receiverParamTypeSignature .addTypeAnnotation (typePath ,
1626+ annotationInfo );
16091627 }
1610- // TODO: is this the right way to apply a receiver type annotation?
1611- final TypeSignature receiverParamTypeSignature = paramTypeSignatures
1612- .get (0 );
1613- receiverParamTypeSignature .addTypeAnnotation (typePath , annotationInfo );
16141628 } else if (targetType == 0x16 ) {
16151629 // Type in formal parameter declaration of method, constructor,
16161630 // or lambda expression
@@ -1624,8 +1638,13 @@ public void decorate(final MethodTypeSignature methodTypeSignature) {
16241638 }
16251639 } else if (targetType == 0x17 ) {
16261640 // Type in throws clause of method or constructor
1627- methodTypeSignature .getThrowsSignatures ().get (throwsTypeIndex )
1628- .addTypeAnnotation (typePath , annotationInfo );
1641+ final List <ClassRefOrTypeVariableSignature > throwsSignatures = //
1642+ methodTypeSignature .getThrowsSignatures ();
1643+ if (throwsSignatures != null
1644+ && throwsTypeIndex < throwsSignatures .size ()) {
1645+ throwsSignatures .get (throwsTypeIndex ).addTypeAnnotation (typePath ,
1646+ annotationInfo );
1647+ }
16291648 }
16301649 }
16311650 });
@@ -1741,8 +1760,12 @@ private void readClassAttributes() throws IOException, ClassfileFormatException
17411760 public void decorate (final ClassTypeSignature classTypeSignature ) {
17421761 if (targetType == 0x00 ) {
17431762 // Type parameter declaration of generic class or interface
1744- classTypeSignature .getTypeParameters ().get (typeParameterIndex )
1745- .addTypeAnnotation (typePath , annotationInfo );
1763+ final List <TypeParameter > typeParameters = classTypeSignature
1764+ .getTypeParameters ();
1765+ if (typeParameters != null && typeParameterIndex < typeParameters .size ()) {
1766+ typeParameters .get (typeParameterIndex ).addTypeAnnotation (typePath ,
1767+ annotationInfo );
1768+ }
17461769 } else if (targetType == 0x10 ) {
17471770 if (supertypeIndex == 65535 ) {
17481771 // Type in extends clause of class declaration
@@ -1755,14 +1778,18 @@ public void decorate(final ClassTypeSignature classTypeSignature) {
17551778 }
17561779 } else if (targetType == 0x11 ) {
17571780 // Type in bound of type parameter declaration of generic class or interface
1758- final TypeParameter typeParameter = classTypeSignature .getTypeParameters ()
1759- .get (typeParameterIndex );
1760- // TODO: documentation does not specify if bound index should be treated this way *******************
1761- if (boundIndex == 0 ) {
1762- typeParameter .getClassBound ().addTypeAnnotation (typePath , annotationInfo );
1763- } else {
1764- typeParameter .getInterfaceBounds ().get (boundIndex - 1 )
1765- .addTypeAnnotation (typePath , annotationInfo );
1781+ final List <TypeParameter > typeParameters = classTypeSignature
1782+ .getTypeParameters ();
1783+ if (typeParameters != null && typeParameterIndex < typeParameters .size ()) {
1784+ final TypeParameter typeParameter = typeParameters .get (typeParameterIndex );
1785+ // boundIndex == 0 => class bound; boundIndex > 0 => interface bound
1786+ if (boundIndex == 0 ) {
1787+ typeParameter .getClassBound ().addTypeAnnotation (typePath ,
1788+ annotationInfo );
1789+ } else {
1790+ typeParameter .getInterfaceBounds ().get (boundIndex - 1 )
1791+ .addTypeAnnotation (typePath , annotationInfo );
1792+ }
17661793 }
17671794 }
17681795 }
0 commit comments