groovy-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Eric Milles (JIRA)" <>
Subject [jira] [Created] (GROOVY-8313) NullPointerException in TypeResolver when using generic array return type
Date Sat, 09 Sep 2017 14:17:00 GMT
Eric Milles created GROOVY-8313:

             Summary: NullPointerException in TypeResolver when using generic array return
                 Key: GROOVY-8313
             Project: Groovy
          Issue Type: Bug
            Reporter: Eric Milles

I think this is related to GROOVY-6899.  I've been trying to isolate this for some time now:  When using a generic array type as a
return value, the bridge method is written improperly.

public interface MultiIndexed<PK, SK> {
  PK getPrimaryKey();
  SK[] getSecondaryKeys();

class MIData implements MultiIndexed<Integer, String> {
  final String value
  final Integer primaryKey
  final String[] secondaryKeys

  MIData(String val, Integer pk, String... sk) {
    this.value = val
    this.primaryKey = pk
    this.secondaryKeys = sk

javap on MiData.class shows {{public final SK[] getSecondaryKeys();}}.  The equivalent Java
class shows a different signature for the bridge method: {{public java.lang.Object[] getSecondaryKeys();}}.

This causes an NPE under Introspector when bean info is trying to be resolved.
    at com.sun.beans.TypeResolver.resolve(
    at com.sun.beans.TypeResolver.resolve(
    at com.sun.beans.TypeResolver.resolveInClass(
    at java.beans.FeatureDescriptor.getReturnType(
    at java.beans.Introspector.getTargetEventInfo(
    at java.beans.Introspector.getBeanInfo(
    at java.beans.Introspector.getBeanInfo(
    at groovy.lang.MetaClassImpl$
    at Method)
    at groovy.lang.MetaClassImpl.addProperties(
    at groovy.lang.MetaClassImpl.initialize(
    at org.codehaus.groovy.reflection.ClassInfo.getMetaClassUnderLock(
    at org.codehaus.groovy.reflection.ClassInfo.getMetaClass(
    at MiData.$getStaticMetaClass(MiData.groovy)
    at MiData.<init>(MiData.groovy)

class Main {
  static void main(String[] args) {
    def data = new MIData('V', 1, 'B')
    print 'no error'

I think this can be fixed in {{Verifier.getCovariantImplementation}}, like this:
        // if we reach this point we have at least one parameter or return type, that
        // is different in its specified form. That means we have to create a bridge method!
        MethodNode newMethod = new MethodNode(
                overridingMethod.getModifiers() | ACC_SYNTHETIC | ACC_BRIDGE,
                // GRECLIPSE edit
                // GRECLIPSE end

This message was sent by Atlassian JIRA

View raw message