You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@wink.apache.org by "Georg Sander (Created) (JIRA)" <ji...@apache.org> on 2012/03/02 12:54:58 UTC

[jira] [Created] (WINK-363) Failure to find array entity providers (such as ByteArrayProvider) in Java 7

Failure to find array entity providers (such as ByteArrayProvider) in Java 7
----------------------------------------------------------------------------

                 Key: WINK-363
                 URL: https://issues.apache.org/jira/browse/WINK-363
             Project: Wink
          Issue Type: Bug
          Components: Providers
    Affects Versions: 1.1.3
         Environment: Linux, Java 1.7.0-b147
            Reporter: Georg Sander


The ByteArrayProvider is properly registered and is found through ProvidersRegistry in Java 6,but not in Java 7. The effect is a consequence of Java bug http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=5041784 which got fixed in Java 7. It can also affect other array entity providers.

Explanation: 

ProvidersRegistry collects the providers for the target type byte[] by checking whether the provider type and the target type are assignable. The corresponding utilities are in GenericsUtils. To determine the provider type, GenericsUtil.getGenericInterfaceParamType retrieves the type from the generic interfaces of ByteArrayProvider. The type parameters in the generic interfaces are represented as java.lang.reflect.Type in Java 6 but as java.lang.Class in Java 7. As consequence, the method GenericsUtils.isAssignableFrom fails to see that the type parameter is an array, hence it returns that byte[] is not assignable to the retrieved type of ByteArrayProvider.

Here is a simple Java program that explains the difference between Java 6 and Java 7. 

In Java 6, the output is:

Type Parameter byte[]
Type Parameter class class sun.reflect.generics.reflectiveObjects.GenericArrayTypeImpl
Is Generic Array true

In Java 7, the output is:

Type Parameter class [B
Type Parameter class class java.lang.Class
Is Generic Array false

------------------------------------------------
import java.lang.reflect.GenericArrayType;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;

public class Test
{

  public static void main(String[] args) {


    Class cls = ByteArrayProvider.class;
    Type[] interfaces = cls.getGenericInterfaces();
    for (Type type : interfaces) {
      if (type instanceof ParameterizedType) {
        ParameterizedType pType = (ParameterizedType)type;
        Type t = pType.getActualTypeArguments()[0];
        System.err.println("Type Parameter " + t);
        System.err.println("Type Parameter class " + t.getClass());
        System.err.println("Is Generic Array " + (t instanceof GenericArrayType));
      }
    }
  }
}


interface MessageBodyWriter<T> { }

class ByteArrayProvider implements MessageBodyWriter<byte[]> { }
-------------------------


I suggest the following fix in GenericsUtils (tested locally in Wink 1.1.3):


    public static boolean isAssignableFrom(Type type, Class<?> cls) {
        if (cls.isArray()) {
            if (type instanceof GenericArrayType) {
                // JDK 6 case
                GenericArrayType genericArray = (GenericArrayType)type;
                Class<?> componentType = cls.getComponentType();
                return isAssignableFrom(genericArray.getGenericComponentType(), componentType);
            }
            else if ((type instanceof Class<?>) && ((Class<?>)type).isArray()) {
                // JDK 7 case
                Class<?> componentType1 = ((Class<?>)type).getComponentType();
                Class<?> componentType2 = cls.getComponentType();
                return isAssignableFrom(componentType1, componentType2);
            }
        } else {
            if (type instanceof GenericArrayType == false) {
                Class<?> classType = getClassType(type, null);
                if (classType == Object.class || classType.isAssignableFrom(cls)) {
                    return true;
                }
            }
        }
        return false;
    }



--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Commented] (WINK-363) Failure to find array entity providers (such as ByteArrayProvider) in Java 7

Posted by "Michael Fiedler (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/WINK-363?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13427636#comment-13427636 ] 

Michael Fiedler commented on WINK-363:
--------------------------------------

[~luciano resende] Great news.   What is the outlook for getting a Wink.next build with the fix incorporated? 
                
> Failure to find array entity providers (such as ByteArrayProvider) in Java 7
> ----------------------------------------------------------------------------
>
>                 Key: WINK-363
>                 URL: https://issues.apache.org/jira/browse/WINK-363
>             Project: Wink
>          Issue Type: Bug
>          Components: Providers
>    Affects Versions: 1.2
>         Environment: Linux, Java 1.7.0-b147
>            Reporter: Georg Sander
>             Fix For: 1.3
>
>         Attachments: GenericsUtils.java
>
>
> The ByteArrayProvider is properly registered and is found through ProvidersRegistry in Java 6,but not in Java 7. The effect is a consequence of Java bug http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=5041784 which got fixed in Java 7. It can also affect other array entity providers.
> Explanation: 
> ProvidersRegistry collects the providers for the target type byte[] by checking whether the provider type and the target type are assignable. The corresponding utilities are in GenericsUtils. To determine the provider type, GenericsUtil.getGenericInterfaceParamType retrieves the type from the generic interfaces of ByteArrayProvider. The type parameters in the generic interfaces are represented as java.lang.reflect.Type in Java 6 but as java.lang.Class in Java 7. As consequence, the method GenericsUtils.isAssignableFrom fails to see that the type parameter is an array, hence it returns that byte[] is not assignable to the retrieved type of ByteArrayProvider.
> Here is a simple Java program that explains the difference between Java 6 and Java 7. 
> In Java 6, the output is:
> Type Parameter byte[]
> Type Parameter class class sun.reflect.generics.reflectiveObjects.GenericArrayTypeImpl
> Is Generic Array true
> In Java 7, the output is:
> Type Parameter class [B
> Type Parameter class class java.lang.Class
> Is Generic Array false
> {code}
> import java.lang.reflect.GenericArrayType;
> import java.lang.reflect.ParameterizedType;
> import java.lang.reflect.Type;
> public class Test
> {
>   public static void main(String[] args) {
>     Class cls = ByteArrayProvider.class;
>     Type[] interfaces = cls.getGenericInterfaces();
>     for (Type type : interfaces) {
>       if (type instanceof ParameterizedType) {
>         ParameterizedType pType = (ParameterizedType)type;
>         Type t = pType.getActualTypeArguments()[0];
>         System.err.println("Type Parameter " + t);
>         System.err.println("Type Parameter class " + t.getClass());
>         System.err.println("Is Generic Array " + (t instanceof GenericArrayType));
>       }
>     }
>   }
> }
> interface MessageBodyWriter<T> { }
> class ByteArrayProvider implements MessageBodyWriter<byte[]> { }
> {code}
> I suggest the following fix in GenericsUtils (tested locally in Wink 1.1.3):
> {code:title=GenericsUtils.isAssignableFrom|borderStyle=solid}
>     public static boolean isAssignableFrom(Type type, Class<?> cls) {
>         if (cls.isArray()) {
>             if (type instanceof GenericArrayType) {
>                 GenericArrayType genericArray = (GenericArrayType)type;
>                 Class<?> componentType = cls.getComponentType();
>                 return isAssignableFrom(genericArray.getGenericComponentType(), componentType);
>             }
>             else if ((type instanceof Class<?>) && ((Class<?>)type).isArray()) {
>                 Class<?> componentType1 = ((Class<?>)type).getComponentType();
>                 Class<?> componentType2 = cls.getComponentType();
>                 return isAssignableFrom(componentType1, componentType2);
>             }
>         } else {
>             if (type instanceof GenericArrayType == false) {
>                 Class<?> classType = getClassType(type, null);
>                 if (classType == Object.class || classType.isAssignableFrom(cls)) {
>                     return true;
>                 }
>             }
>         }
>         return false;
>     }
> {code}

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Updated] (WINK-363) Failure to find array entity providers (such as ByteArrayProvider) in Java 7

Posted by "Luciano Resende (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/WINK-363?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Luciano Resende updated WINK-363:
---------------------------------

    Affects Version/s:     (was: 1.1.3)
                       1.2
        Fix Version/s: 1.3
    
> Failure to find array entity providers (such as ByteArrayProvider) in Java 7
> ----------------------------------------------------------------------------
>
>                 Key: WINK-363
>                 URL: https://issues.apache.org/jira/browse/WINK-363
>             Project: Wink
>          Issue Type: Bug
>          Components: Providers
>    Affects Versions: 1.2
>         Environment: Linux, Java 1.7.0-b147
>            Reporter: Georg Sander
>             Fix For: 1.3
>
>         Attachments: GenericsUtils.java
>
>
> The ByteArrayProvider is properly registered and is found through ProvidersRegistry in Java 6,but not in Java 7. The effect is a consequence of Java bug http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=5041784 which got fixed in Java 7. It can also affect other array entity providers.
> Explanation: 
> ProvidersRegistry collects the providers for the target type byte[] by checking whether the provider type and the target type are assignable. The corresponding utilities are in GenericsUtils. To determine the provider type, GenericsUtil.getGenericInterfaceParamType retrieves the type from the generic interfaces of ByteArrayProvider. The type parameters in the generic interfaces are represented as java.lang.reflect.Type in Java 6 but as java.lang.Class in Java 7. As consequence, the method GenericsUtils.isAssignableFrom fails to see that the type parameter is an array, hence it returns that byte[] is not assignable to the retrieved type of ByteArrayProvider.
> Here is a simple Java program that explains the difference between Java 6 and Java 7. 
> In Java 6, the output is:
> Type Parameter byte[]
> Type Parameter class class sun.reflect.generics.reflectiveObjects.GenericArrayTypeImpl
> Is Generic Array true
> In Java 7, the output is:
> Type Parameter class [B
> Type Parameter class class java.lang.Class
> Is Generic Array false
> {code}
> import java.lang.reflect.GenericArrayType;
> import java.lang.reflect.ParameterizedType;
> import java.lang.reflect.Type;
> public class Test
> {
>   public static void main(String[] args) {
>     Class cls = ByteArrayProvider.class;
>     Type[] interfaces = cls.getGenericInterfaces();
>     for (Type type : interfaces) {
>       if (type instanceof ParameterizedType) {
>         ParameterizedType pType = (ParameterizedType)type;
>         Type t = pType.getActualTypeArguments()[0];
>         System.err.println("Type Parameter " + t);
>         System.err.println("Type Parameter class " + t.getClass());
>         System.err.println("Is Generic Array " + (t instanceof GenericArrayType));
>       }
>     }
>   }
> }
> interface MessageBodyWriter<T> { }
> class ByteArrayProvider implements MessageBodyWriter<byte[]> { }
> {code}
> I suggest the following fix in GenericsUtils (tested locally in Wink 1.1.3):
> {code:title=GenericsUtils.isAssignableFrom|borderStyle=solid}
>     public static boolean isAssignableFrom(Type type, Class<?> cls) {
>         if (cls.isArray()) {
>             if (type instanceof GenericArrayType) {
>                 GenericArrayType genericArray = (GenericArrayType)type;
>                 Class<?> componentType = cls.getComponentType();
>                 return isAssignableFrom(genericArray.getGenericComponentType(), componentType);
>             }
>             else if ((type instanceof Class<?>) && ((Class<?>)type).isArray()) {
>                 Class<?> componentType1 = ((Class<?>)type).getComponentType();
>                 Class<?> componentType2 = cls.getComponentType();
>                 return isAssignableFrom(componentType1, componentType2);
>             }
>         } else {
>             if (type instanceof GenericArrayType == false) {
>                 Class<?> classType = getClassType(type, null);
>                 if (classType == Object.class || classType.isAssignableFrom(cls)) {
>                     return true;
>                 }
>             }
>         }
>         return false;
>     }
> {code}

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Commented] (WINK-363) Failure to find array entity providers (such as ByteArrayProvider) in Java 7

Posted by "Michael Fiedler (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/WINK-363?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13425978#comment-13425978 ] 

Michael Fiedler commented on WINK-363:
--------------------------------------

[~kevan] Any chance of getting this in a build?  I verified the proposed patch on 1.2.0 and can confirm it fixes the issue.   The wink-commons JUnits actually fail without the patch on and pass with it on.  I can open a separate issue for the JUNit failure if that helps.

My JRE:

java version "1.7.0"
Java(TM) SE Runtime Environment (build pwa6470sr1-20120405_01(SR1))
IBM J9 VM (build 2.6, JRE 1.7.0 Windows Server 2008 R2 amd64-64 20120322_106209
(JIT enabled, AOT enabled)
J9VM - R26_Java726_SR1_20120322_1720_B106209
JIT  - r11_20120322_22976
GC   - R26_Java726_SR1_20120322_1720_B106209
J9CL - 20120322_106209)
JCL - 20120322_01 based on Oracle 7u3-b05
                
> Failure to find array entity providers (such as ByteArrayProvider) in Java 7
> ----------------------------------------------------------------------------
>
>                 Key: WINK-363
>                 URL: https://issues.apache.org/jira/browse/WINK-363
>             Project: Wink
>          Issue Type: Bug
>          Components: Providers
>    Affects Versions: 1.1.3
>         Environment: Linux, Java 1.7.0-b147
>            Reporter: Georg Sander
>         Attachments: GenericsUtils.java
>
>
> The ByteArrayProvider is properly registered and is found through ProvidersRegistry in Java 6,but not in Java 7. The effect is a consequence of Java bug http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=5041784 which got fixed in Java 7. It can also affect other array entity providers.
> Explanation: 
> ProvidersRegistry collects the providers for the target type byte[] by checking whether the provider type and the target type are assignable. The corresponding utilities are in GenericsUtils. To determine the provider type, GenericsUtil.getGenericInterfaceParamType retrieves the type from the generic interfaces of ByteArrayProvider. The type parameters in the generic interfaces are represented as java.lang.reflect.Type in Java 6 but as java.lang.Class in Java 7. As consequence, the method GenericsUtils.isAssignableFrom fails to see that the type parameter is an array, hence it returns that byte[] is not assignable to the retrieved type of ByteArrayProvider.
> Here is a simple Java program that explains the difference between Java 6 and Java 7. 
> In Java 6, the output is:
> Type Parameter byte[]
> Type Parameter class class sun.reflect.generics.reflectiveObjects.GenericArrayTypeImpl
> Is Generic Array true
> In Java 7, the output is:
> Type Parameter class [B
> Type Parameter class class java.lang.Class
> Is Generic Array false
> {code}
> import java.lang.reflect.GenericArrayType;
> import java.lang.reflect.ParameterizedType;
> import java.lang.reflect.Type;
> public class Test
> {
>   public static void main(String[] args) {
>     Class cls = ByteArrayProvider.class;
>     Type[] interfaces = cls.getGenericInterfaces();
>     for (Type type : interfaces) {
>       if (type instanceof ParameterizedType) {
>         ParameterizedType pType = (ParameterizedType)type;
>         Type t = pType.getActualTypeArguments()[0];
>         System.err.println("Type Parameter " + t);
>         System.err.println("Type Parameter class " + t.getClass());
>         System.err.println("Is Generic Array " + (t instanceof GenericArrayType));
>       }
>     }
>   }
> }
> interface MessageBodyWriter<T> { }
> class ByteArrayProvider implements MessageBodyWriter<byte[]> { }
> {code}
> I suggest the following fix in GenericsUtils (tested locally in Wink 1.1.3):
> {code:title=GenericsUtils.isAssignableFrom|borderStyle=solid}
>     public static boolean isAssignableFrom(Type type, Class<?> cls) {
>         if (cls.isArray()) {
>             if (type instanceof GenericArrayType) {
>                 GenericArrayType genericArray = (GenericArrayType)type;
>                 Class<?> componentType = cls.getComponentType();
>                 return isAssignableFrom(genericArray.getGenericComponentType(), componentType);
>             }
>             else if ((type instanceof Class<?>) && ((Class<?>)type).isArray()) {
>                 Class<?> componentType1 = ((Class<?>)type).getComponentType();
>                 Class<?> componentType2 = cls.getComponentType();
>                 return isAssignableFrom(componentType1, componentType2);
>             }
>         } else {
>             if (type instanceof GenericArrayType == false) {
>                 Class<?> classType = getClassType(type, null);
>                 if (classType == Object.class || classType.isAssignableFrom(cls)) {
>                     return true;
>                 }
>             }
>         }
>         return false;
>     }
> {code}

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Commented] (WINK-363) Failure to find array entity providers (such as ByteArrayProvider) in Java 7

Posted by "Michael Fiedler (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/WINK-363?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13426009#comment-13426009 ] 

Michael Fiedler commented on WINK-363:
--------------------------------------

I see that's probably the wrong person to ping in my comment.  Project leads/committers, can this be a candidate for an upcoming build?  
                
> Failure to find array entity providers (such as ByteArrayProvider) in Java 7
> ----------------------------------------------------------------------------
>
>                 Key: WINK-363
>                 URL: https://issues.apache.org/jira/browse/WINK-363
>             Project: Wink
>          Issue Type: Bug
>          Components: Providers
>    Affects Versions: 1.1.3
>         Environment: Linux, Java 1.7.0-b147
>            Reporter: Georg Sander
>         Attachments: GenericsUtils.java
>
>
> The ByteArrayProvider is properly registered and is found through ProvidersRegistry in Java 6,but not in Java 7. The effect is a consequence of Java bug http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=5041784 which got fixed in Java 7. It can also affect other array entity providers.
> Explanation: 
> ProvidersRegistry collects the providers for the target type byte[] by checking whether the provider type and the target type are assignable. The corresponding utilities are in GenericsUtils. To determine the provider type, GenericsUtil.getGenericInterfaceParamType retrieves the type from the generic interfaces of ByteArrayProvider. The type parameters in the generic interfaces are represented as java.lang.reflect.Type in Java 6 but as java.lang.Class in Java 7. As consequence, the method GenericsUtils.isAssignableFrom fails to see that the type parameter is an array, hence it returns that byte[] is not assignable to the retrieved type of ByteArrayProvider.
> Here is a simple Java program that explains the difference between Java 6 and Java 7. 
> In Java 6, the output is:
> Type Parameter byte[]
> Type Parameter class class sun.reflect.generics.reflectiveObjects.GenericArrayTypeImpl
> Is Generic Array true
> In Java 7, the output is:
> Type Parameter class [B
> Type Parameter class class java.lang.Class
> Is Generic Array false
> {code}
> import java.lang.reflect.GenericArrayType;
> import java.lang.reflect.ParameterizedType;
> import java.lang.reflect.Type;
> public class Test
> {
>   public static void main(String[] args) {
>     Class cls = ByteArrayProvider.class;
>     Type[] interfaces = cls.getGenericInterfaces();
>     for (Type type : interfaces) {
>       if (type instanceof ParameterizedType) {
>         ParameterizedType pType = (ParameterizedType)type;
>         Type t = pType.getActualTypeArguments()[0];
>         System.err.println("Type Parameter " + t);
>         System.err.println("Type Parameter class " + t.getClass());
>         System.err.println("Is Generic Array " + (t instanceof GenericArrayType));
>       }
>     }
>   }
> }
> interface MessageBodyWriter<T> { }
> class ByteArrayProvider implements MessageBodyWriter<byte[]> { }
> {code}
> I suggest the following fix in GenericsUtils (tested locally in Wink 1.1.3):
> {code:title=GenericsUtils.isAssignableFrom|borderStyle=solid}
>     public static boolean isAssignableFrom(Type type, Class<?> cls) {
>         if (cls.isArray()) {
>             if (type instanceof GenericArrayType) {
>                 GenericArrayType genericArray = (GenericArrayType)type;
>                 Class<?> componentType = cls.getComponentType();
>                 return isAssignableFrom(genericArray.getGenericComponentType(), componentType);
>             }
>             else if ((type instanceof Class<?>) && ((Class<?>)type).isArray()) {
>                 Class<?> componentType1 = ((Class<?>)type).getComponentType();
>                 Class<?> componentType2 = cls.getComponentType();
>                 return isAssignableFrom(componentType1, componentType2);
>             }
>         } else {
>             if (type instanceof GenericArrayType == false) {
>                 Class<?> classType = getClassType(type, null);
>                 if (classType == Object.class || classType.isAssignableFrom(cls)) {
>                     return true;
>                 }
>             }
>         }
>         return false;
>     }
> {code}

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Resolved] (WINK-363) Failure to find array entity providers (such as ByteArrayProvider) in Java 7

Posted by "Luciano Resende (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/WINK-363?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Luciano Resende resolved WINK-363.
----------------------------------

    Resolution: Fixed

Patch applied into trunk. This fixes the issue with IBM JDK7 (latest)
                
> Failure to find array entity providers (such as ByteArrayProvider) in Java 7
> ----------------------------------------------------------------------------
>
>                 Key: WINK-363
>                 URL: https://issues.apache.org/jira/browse/WINK-363
>             Project: Wink
>          Issue Type: Bug
>          Components: Providers
>    Affects Versions: 1.2
>         Environment: Linux, Java 1.7.0-b147
>            Reporter: Georg Sander
>         Attachments: GenericsUtils.java
>
>
> The ByteArrayProvider is properly registered and is found through ProvidersRegistry in Java 6,but not in Java 7. The effect is a consequence of Java bug http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=5041784 which got fixed in Java 7. It can also affect other array entity providers.
> Explanation: 
> ProvidersRegistry collects the providers for the target type byte[] by checking whether the provider type and the target type are assignable. The corresponding utilities are in GenericsUtils. To determine the provider type, GenericsUtil.getGenericInterfaceParamType retrieves the type from the generic interfaces of ByteArrayProvider. The type parameters in the generic interfaces are represented as java.lang.reflect.Type in Java 6 but as java.lang.Class in Java 7. As consequence, the method GenericsUtils.isAssignableFrom fails to see that the type parameter is an array, hence it returns that byte[] is not assignable to the retrieved type of ByteArrayProvider.
> Here is a simple Java program that explains the difference between Java 6 and Java 7. 
> In Java 6, the output is:
> Type Parameter byte[]
> Type Parameter class class sun.reflect.generics.reflectiveObjects.GenericArrayTypeImpl
> Is Generic Array true
> In Java 7, the output is:
> Type Parameter class [B
> Type Parameter class class java.lang.Class
> Is Generic Array false
> {code}
> import java.lang.reflect.GenericArrayType;
> import java.lang.reflect.ParameterizedType;
> import java.lang.reflect.Type;
> public class Test
> {
>   public static void main(String[] args) {
>     Class cls = ByteArrayProvider.class;
>     Type[] interfaces = cls.getGenericInterfaces();
>     for (Type type : interfaces) {
>       if (type instanceof ParameterizedType) {
>         ParameterizedType pType = (ParameterizedType)type;
>         Type t = pType.getActualTypeArguments()[0];
>         System.err.println("Type Parameter " + t);
>         System.err.println("Type Parameter class " + t.getClass());
>         System.err.println("Is Generic Array " + (t instanceof GenericArrayType));
>       }
>     }
>   }
> }
> interface MessageBodyWriter<T> { }
> class ByteArrayProvider implements MessageBodyWriter<byte[]> { }
> {code}
> I suggest the following fix in GenericsUtils (tested locally in Wink 1.1.3):
> {code:title=GenericsUtils.isAssignableFrom|borderStyle=solid}
>     public static boolean isAssignableFrom(Type type, Class<?> cls) {
>         if (cls.isArray()) {
>             if (type instanceof GenericArrayType) {
>                 GenericArrayType genericArray = (GenericArrayType)type;
>                 Class<?> componentType = cls.getComponentType();
>                 return isAssignableFrom(genericArray.getGenericComponentType(), componentType);
>             }
>             else if ((type instanceof Class<?>) && ((Class<?>)type).isArray()) {
>                 Class<?> componentType1 = ((Class<?>)type).getComponentType();
>                 Class<?> componentType2 = cls.getComponentType();
>                 return isAssignableFrom(componentType1, componentType2);
>             }
>         } else {
>             if (type instanceof GenericArrayType == false) {
>                 Class<?> classType = getClassType(type, null);
>                 if (classType == Object.class || classType.isAssignableFrom(cls)) {
>                     return true;
>                 }
>             }
>         }
>         return false;
>     }
> {code}

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Commented] (WINK-363) Failure to find array entity providers (such as ByteArrayProvider) in Java 7

Posted by "Luciano Resende (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/WINK-363?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13427738#comment-13427738 ] 

Luciano Resende commented on WINK-363:
--------------------------------------

Are you actually asking for a official release (e.g. 1.2.1) otherwise Jenkins builds are running and should be available.
                
> Failure to find array entity providers (such as ByteArrayProvider) in Java 7
> ----------------------------------------------------------------------------
>
>                 Key: WINK-363
>                 URL: https://issues.apache.org/jira/browse/WINK-363
>             Project: Wink
>          Issue Type: Bug
>          Components: Providers
>    Affects Versions: 1.2
>         Environment: Linux, Java 1.7.0-b147
>            Reporter: Georg Sander
>             Fix For: 1.3
>
>         Attachments: GenericsUtils.java
>
>
> The ByteArrayProvider is properly registered and is found through ProvidersRegistry in Java 6,but not in Java 7. The effect is a consequence of Java bug http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=5041784 which got fixed in Java 7. It can also affect other array entity providers.
> Explanation: 
> ProvidersRegistry collects the providers for the target type byte[] by checking whether the provider type and the target type are assignable. The corresponding utilities are in GenericsUtils. To determine the provider type, GenericsUtil.getGenericInterfaceParamType retrieves the type from the generic interfaces of ByteArrayProvider. The type parameters in the generic interfaces are represented as java.lang.reflect.Type in Java 6 but as java.lang.Class in Java 7. As consequence, the method GenericsUtils.isAssignableFrom fails to see that the type parameter is an array, hence it returns that byte[] is not assignable to the retrieved type of ByteArrayProvider.
> Here is a simple Java program that explains the difference between Java 6 and Java 7. 
> In Java 6, the output is:
> Type Parameter byte[]
> Type Parameter class class sun.reflect.generics.reflectiveObjects.GenericArrayTypeImpl
> Is Generic Array true
> In Java 7, the output is:
> Type Parameter class [B
> Type Parameter class class java.lang.Class
> Is Generic Array false
> {code}
> import java.lang.reflect.GenericArrayType;
> import java.lang.reflect.ParameterizedType;
> import java.lang.reflect.Type;
> public class Test
> {
>   public static void main(String[] args) {
>     Class cls = ByteArrayProvider.class;
>     Type[] interfaces = cls.getGenericInterfaces();
>     for (Type type : interfaces) {
>       if (type instanceof ParameterizedType) {
>         ParameterizedType pType = (ParameterizedType)type;
>         Type t = pType.getActualTypeArguments()[0];
>         System.err.println("Type Parameter " + t);
>         System.err.println("Type Parameter class " + t.getClass());
>         System.err.println("Is Generic Array " + (t instanceof GenericArrayType));
>       }
>     }
>   }
> }
> interface MessageBodyWriter<T> { }
> class ByteArrayProvider implements MessageBodyWriter<byte[]> { }
> {code}
> I suggest the following fix in GenericsUtils (tested locally in Wink 1.1.3):
> {code:title=GenericsUtils.isAssignableFrom|borderStyle=solid}
>     public static boolean isAssignableFrom(Type type, Class<?> cls) {
>         if (cls.isArray()) {
>             if (type instanceof GenericArrayType) {
>                 GenericArrayType genericArray = (GenericArrayType)type;
>                 Class<?> componentType = cls.getComponentType();
>                 return isAssignableFrom(genericArray.getGenericComponentType(), componentType);
>             }
>             else if ((type instanceof Class<?>) && ((Class<?>)type).isArray()) {
>                 Class<?> componentType1 = ((Class<?>)type).getComponentType();
>                 Class<?> componentType2 = cls.getComponentType();
>                 return isAssignableFrom(componentType1, componentType2);
>             }
>         } else {
>             if (type instanceof GenericArrayType == false) {
>                 Class<?> classType = getClassType(type, null);
>                 if (classType == Object.class || classType.isAssignableFrom(cls)) {
>                     return true;
>                 }
>             }
>         }
>         return false;
>     }
> {code}

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Updated] (WINK-363) Failure to find array entity providers (such as ByteArrayProvider) in Java 7

Posted by "Georg Sander (Updated) (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/WINK-363?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Georg Sander updated WINK-363:
------------------------------

    Description: 
The ByteArrayProvider is properly registered and is found through ProvidersRegistry in Java 6,but not in Java 7. The effect is a consequence of Java bug http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=5041784 which got fixed in Java 7. It can also affect other array entity providers.

Explanation: 

ProvidersRegistry collects the providers for the target type byte[] by checking whether the provider type and the target type are assignable. The corresponding utilities are in GenericsUtils. To determine the provider type, GenericsUtil.getGenericInterfaceParamType retrieves the type from the generic interfaces of ByteArrayProvider. The type parameters in the generic interfaces are represented as java.lang.reflect.Type in Java 6 but as java.lang.Class in Java 7. As consequence, the method GenericsUtils.isAssignableFrom fails to see that the type parameter is an array, hence it returns that byte[] is not assignable to the retrieved type of ByteArrayProvider.

Here is a simple Java program that explains the difference between Java 6 and Java 7. 

In Java 6, the output is:

Type Parameter byte[]
Type Parameter class class sun.reflect.generics.reflectiveObjects.GenericArrayTypeImpl
Is Generic Array true

In Java 7, the output is:

Type Parameter class [B
Type Parameter class class java.lang.Class
Is Generic Array false

------------------------------------------------
{code}
import java.lang.reflect.GenericArrayType;

import java.lang.reflect.ParameterizedType;

import java.lang.reflect.Type;

public class Test
{

  public static void main(String[] args) {
    Class cls = ByteArrayProvider.class;
    Type[] interfaces = cls.getGenericInterfaces();
    for (Type type : interfaces) {
      if (type instanceof ParameterizedType) {
        ParameterizedType pType = (ParameterizedType)type;
        Type t = pType.getActualTypeArguments()[0];
        System.err.println("Type Parameter " + t);
        System.err.println("Type Parameter class " + t.getClass());
        System.err.println("Is Generic Array " + (t instanceof GenericArrayType));
      }
    }
  }
}
{code}

interface MessageBodyWriter<T> { }

class ByteArrayProvider implements MessageBodyWriter<byte[]> { }

-------------------------


I suggest the following fix in GenericsUtils (tested locally in Wink 1.1.3):

{code:title=GenericsUtils.isAssignableFrom|borderStyle=solid}
    public static boolean isAssignableFrom(Type type, Class<?> cls) {
        if (cls.isArray()) {
            if (type instanceof GenericArrayType) {
                GenericArrayType genericArray = (GenericArrayType)type;
                Class<?> componentType = cls.getComponentType();
                return isAssignableFrom(genericArray.getGenericComponentType(), componentType);
            }
            else if ((type instanceof Class<?>) && ((Class<?>)type).isArray()) {
                Class<?> componentType1 = ((Class<?>)type).getComponentType();
                Class<?> componentType2 = cls.getComponentType();
                return isAssignableFrom(componentType1, componentType2);
            }
        } else {
            if (type instanceof GenericArrayType == false) {
                Class<?> classType = getClassType(type, null);
                if (classType == Object.class || classType.isAssignableFrom(cls)) {
                    return true;
                }
            }
        }
        return false;
    }
{code}


  was:
The ByteArrayProvider is properly registered and is found through ProvidersRegistry in Java 6,but not in Java 7. The effect is a consequence of Java bug http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=5041784 which got fixed in Java 7. It can also affect other array entity providers.

Explanation: 

ProvidersRegistry collects the providers for the target type byte[] by checking whether the provider type and the target type are assignable. The corresponding utilities are in GenericsUtils. To determine the provider type, GenericsUtil.getGenericInterfaceParamType retrieves the type from the generic interfaces of ByteArrayProvider. The type parameters in the generic interfaces are represented as java.lang.reflect.Type in Java 6 but as java.lang.Class in Java 7. As consequence, the method GenericsUtils.isAssignableFrom fails to see that the type parameter is an array, hence it returns that byte[] is not assignable to the retrieved type of ByteArrayProvider.

Here is a simple Java program that explains the difference between Java 6 and Java 7. 

In Java 6, the output is:

Type Parameter byte[]
Type Parameter class class sun.reflect.generics.reflectiveObjects.GenericArrayTypeImpl
Is Generic Array true

In Java 7, the output is:

Type Parameter class [B
Type Parameter class class java.lang.Class
Is Generic Array false

------------------------------------------------
import java.lang.reflect.GenericArrayType;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;

public class Test
{

  public static void main(String[] args) {


    Class cls = ByteArrayProvider.class;
    Type[] interfaces = cls.getGenericInterfaces();
    for (Type type : interfaces) {
      if (type instanceof ParameterizedType) {
        ParameterizedType pType = (ParameterizedType)type;
        Type t = pType.getActualTypeArguments()[0];
        System.err.println("Type Parameter " + t);
        System.err.println("Type Parameter class " + t.getClass());
        System.err.println("Is Generic Array " + (t instanceof GenericArrayType));
      }
    }
  }
}


interface MessageBodyWriter<T> { }

class ByteArrayProvider implements MessageBodyWriter<byte[]> { }
-------------------------


I suggest the following fix in GenericsUtils (tested locally in Wink 1.1.3):


    public static boolean isAssignableFrom(Type type, Class<?> cls) {
        if (cls.isArray()) {
            if (type instanceof GenericArrayType) {
                // JDK 6 case
                GenericArrayType genericArray = (GenericArrayType)type;
                Class<?> componentType = cls.getComponentType();
                return isAssignableFrom(genericArray.getGenericComponentType(), componentType);
            }
            else if ((type instanceof Class<?>) && ((Class<?>)type).isArray()) {
                // JDK 7 case
                Class<?> componentType1 = ((Class<?>)type).getComponentType();
                Class<?> componentType2 = cls.getComponentType();
                return isAssignableFrom(componentType1, componentType2);
            }
        } else {
            if (type instanceof GenericArrayType == false) {
                Class<?> classType = getClassType(type, null);
                if (classType == Object.class || classType.isAssignableFrom(cls)) {
                    return true;
                }
            }
        }
        return false;
    }



    
> Failure to find array entity providers (such as ByteArrayProvider) in Java 7
> ----------------------------------------------------------------------------
>
>                 Key: WINK-363
>                 URL: https://issues.apache.org/jira/browse/WINK-363
>             Project: Wink
>          Issue Type: Bug
>          Components: Providers
>    Affects Versions: 1.1.3
>         Environment: Linux, Java 1.7.0-b147
>            Reporter: Georg Sander
>
> The ByteArrayProvider is properly registered and is found through ProvidersRegistry in Java 6,but not in Java 7. The effect is a consequence of Java bug http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=5041784 which got fixed in Java 7. It can also affect other array entity providers.
> Explanation: 
> ProvidersRegistry collects the providers for the target type byte[] by checking whether the provider type and the target type are assignable. The corresponding utilities are in GenericsUtils. To determine the provider type, GenericsUtil.getGenericInterfaceParamType retrieves the type from the generic interfaces of ByteArrayProvider. The type parameters in the generic interfaces are represented as java.lang.reflect.Type in Java 6 but as java.lang.Class in Java 7. As consequence, the method GenericsUtils.isAssignableFrom fails to see that the type parameter is an array, hence it returns that byte[] is not assignable to the retrieved type of ByteArrayProvider.
> Here is a simple Java program that explains the difference between Java 6 and Java 7. 
> In Java 6, the output is:
> Type Parameter byte[]
> Type Parameter class class sun.reflect.generics.reflectiveObjects.GenericArrayTypeImpl
> Is Generic Array true
> In Java 7, the output is:
> Type Parameter class [B
> Type Parameter class class java.lang.Class
> Is Generic Array false
> ------------------------------------------------
> {code}
> import java.lang.reflect.GenericArrayType;
> import java.lang.reflect.ParameterizedType;
> import java.lang.reflect.Type;
> public class Test
> {
>   public static void main(String[] args) {
>     Class cls = ByteArrayProvider.class;
>     Type[] interfaces = cls.getGenericInterfaces();
>     for (Type type : interfaces) {
>       if (type instanceof ParameterizedType) {
>         ParameterizedType pType = (ParameterizedType)type;
>         Type t = pType.getActualTypeArguments()[0];
>         System.err.println("Type Parameter " + t);
>         System.err.println("Type Parameter class " + t.getClass());
>         System.err.println("Is Generic Array " + (t instanceof GenericArrayType));
>       }
>     }
>   }
> }
> {code}
> interface MessageBodyWriter<T> { }
> class ByteArrayProvider implements MessageBodyWriter<byte[]> { }
> -------------------------
> I suggest the following fix in GenericsUtils (tested locally in Wink 1.1.3):
> {code:title=GenericsUtils.isAssignableFrom|borderStyle=solid}
>     public static boolean isAssignableFrom(Type type, Class<?> cls) {
>         if (cls.isArray()) {
>             if (type instanceof GenericArrayType) {
>                 GenericArrayType genericArray = (GenericArrayType)type;
>                 Class<?> componentType = cls.getComponentType();
>                 return isAssignableFrom(genericArray.getGenericComponentType(), componentType);
>             }
>             else if ((type instanceof Class<?>) && ((Class<?>)type).isArray()) {
>                 Class<?> componentType1 = ((Class<?>)type).getComponentType();
>                 Class<?> componentType2 = cls.getComponentType();
>                 return isAssignableFrom(componentType1, componentType2);
>             }
>         } else {
>             if (type instanceof GenericArrayType == false) {
>                 Class<?> classType = getClassType(type, null);
>                 if (classType == Object.class || classType.isAssignableFrom(cls)) {
>                     return true;
>                 }
>             }
>         }
>         return false;
>     }
> {code}

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Commented] (WINK-363) Failure to find array entity providers (such as ByteArrayProvider) in Java 7

Posted by "Kevan Miller (Commented) (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/WINK-363?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13221103#comment-13221103 ] 

Kevan Miller commented on WINK-363:
-----------------------------------

Thanks Georg.

Your code above is assumed to be a contribution to the ASF under the Apache License v2 (and thus we could incorporate into Wink).

Attaching the source (preferably as a patch file) to the Jira and clicking the "Grant license to ASF for inclusion in ASF works (as per the Apache License ยง5)" radio button makes the licensing of your contribution explicit.

The latter method is preferred, but not absolutely necessary. Doesn't look like Wink has any documentation on this (something for the to do list).
                
> Failure to find array entity providers (such as ByteArrayProvider) in Java 7
> ----------------------------------------------------------------------------
>
>                 Key: WINK-363
>                 URL: https://issues.apache.org/jira/browse/WINK-363
>             Project: Wink
>          Issue Type: Bug
>          Components: Providers
>    Affects Versions: 1.1.3
>         Environment: Linux, Java 1.7.0-b147
>            Reporter: Georg Sander
>
> The ByteArrayProvider is properly registered and is found through ProvidersRegistry in Java 6,but not in Java 7. The effect is a consequence of Java bug http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=5041784 which got fixed in Java 7. It can also affect other array entity providers.
> Explanation: 
> ProvidersRegistry collects the providers for the target type byte[] by checking whether the provider type and the target type are assignable. The corresponding utilities are in GenericsUtils. To determine the provider type, GenericsUtil.getGenericInterfaceParamType retrieves the type from the generic interfaces of ByteArrayProvider. The type parameters in the generic interfaces are represented as java.lang.reflect.Type in Java 6 but as java.lang.Class in Java 7. As consequence, the method GenericsUtils.isAssignableFrom fails to see that the type parameter is an array, hence it returns that byte[] is not assignable to the retrieved type of ByteArrayProvider.
> Here is a simple Java program that explains the difference between Java 6 and Java 7. 
> In Java 6, the output is:
> Type Parameter byte[]
> Type Parameter class class sun.reflect.generics.reflectiveObjects.GenericArrayTypeImpl
> Is Generic Array true
> In Java 7, the output is:
> Type Parameter class [B
> Type Parameter class class java.lang.Class
> Is Generic Array false
> {code}
> import java.lang.reflect.GenericArrayType;
> import java.lang.reflect.ParameterizedType;
> import java.lang.reflect.Type;
> public class Test
> {
>   public static void main(String[] args) {
>     Class cls = ByteArrayProvider.class;
>     Type[] interfaces = cls.getGenericInterfaces();
>     for (Type type : interfaces) {
>       if (type instanceof ParameterizedType) {
>         ParameterizedType pType = (ParameterizedType)type;
>         Type t = pType.getActualTypeArguments()[0];
>         System.err.println("Type Parameter " + t);
>         System.err.println("Type Parameter class " + t.getClass());
>         System.err.println("Is Generic Array " + (t instanceof GenericArrayType));
>       }
>     }
>   }
> }
> interface MessageBodyWriter<T> { }
> class ByteArrayProvider implements MessageBodyWriter<byte[]> { }
> {code}
> I suggest the following fix in GenericsUtils (tested locally in Wink 1.1.3):
> {code:title=GenericsUtils.isAssignableFrom|borderStyle=solid}
>     public static boolean isAssignableFrom(Type type, Class<?> cls) {
>         if (cls.isArray()) {
>             if (type instanceof GenericArrayType) {
>                 GenericArrayType genericArray = (GenericArrayType)type;
>                 Class<?> componentType = cls.getComponentType();
>                 return isAssignableFrom(genericArray.getGenericComponentType(), componentType);
>             }
>             else if ((type instanceof Class<?>) && ((Class<?>)type).isArray()) {
>                 Class<?> componentType1 = ((Class<?>)type).getComponentType();
>                 Class<?> componentType2 = cls.getComponentType();
>                 return isAssignableFrom(componentType1, componentType2);
>             }
>         } else {
>             if (type instanceof GenericArrayType == false) {
>                 Class<?> classType = getClassType(type, null);
>                 if (classType == Object.class || classType.isAssignableFrom(cls)) {
>                     return true;
>                 }
>             }
>         }
>         return false;
>     }
> {code}

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

       

[jira] [Updated] (WINK-363) Failure to find array entity providers (such as ByteArrayProvider) in Java 7

Posted by "Georg Sander (Updated) (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/WINK-363?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Georg Sander updated WINK-363:
------------------------------

    Description: 
The ByteArrayProvider is properly registered and is found through ProvidersRegistry in Java 6,but not in Java 7. The effect is a consequence of Java bug http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=5041784 which got fixed in Java 7. It can also affect other array entity providers.

Explanation: 

ProvidersRegistry collects the providers for the target type byte[] by checking whether the provider type and the target type are assignable. The corresponding utilities are in GenericsUtils. To determine the provider type, GenericsUtil.getGenericInterfaceParamType retrieves the type from the generic interfaces of ByteArrayProvider. The type parameters in the generic interfaces are represented as java.lang.reflect.Type in Java 6 but as java.lang.Class in Java 7. As consequence, the method GenericsUtils.isAssignableFrom fails to see that the type parameter is an array, hence it returns that byte[] is not assignable to the retrieved type of ByteArrayProvider.

Here is a simple Java program that explains the difference between Java 6 and Java 7. 

In Java 6, the output is:

Type Parameter byte[]
Type Parameter class class sun.reflect.generics.reflectiveObjects.GenericArrayTypeImpl
Is Generic Array true

In Java 7, the output is:

Type Parameter class [B
Type Parameter class class java.lang.Class
Is Generic Array false

{code}
import java.lang.reflect.GenericArrayType;

import java.lang.reflect.ParameterizedType;

import java.lang.reflect.Type;

public class Test
{

  public static void main(String[] args) {
    Class cls = ByteArrayProvider.class;
    Type[] interfaces = cls.getGenericInterfaces();
    for (Type type : interfaces) {
      if (type instanceof ParameterizedType) {
        ParameterizedType pType = (ParameterizedType)type;
        Type t = pType.getActualTypeArguments()[0];
        System.err.println("Type Parameter " + t);
        System.err.println("Type Parameter class " + t.getClass());
        System.err.println("Is Generic Array " + (t instanceof GenericArrayType));
      }
    }
  }
}

interface MessageBodyWriter<T> { }

class ByteArrayProvider implements MessageBodyWriter<byte[]> { }
{code}


I suggest the following fix in GenericsUtils (tested locally in Wink 1.1.3):

{code:title=GenericsUtils.isAssignableFrom|borderStyle=solid}
    public static boolean isAssignableFrom(Type type, Class<?> cls) {
        if (cls.isArray()) {
            if (type instanceof GenericArrayType) {
                GenericArrayType genericArray = (GenericArrayType)type;
                Class<?> componentType = cls.getComponentType();
                return isAssignableFrom(genericArray.getGenericComponentType(), componentType);
            }
            else if ((type instanceof Class<?>) && ((Class<?>)type).isArray()) {
                Class<?> componentType1 = ((Class<?>)type).getComponentType();
                Class<?> componentType2 = cls.getComponentType();
                return isAssignableFrom(componentType1, componentType2);
            }
        } else {
            if (type instanceof GenericArrayType == false) {
                Class<?> classType = getClassType(type, null);
                if (classType == Object.class || classType.isAssignableFrom(cls)) {
                    return true;
                }
            }
        }
        return false;
    }
{code}


  was:
The ByteArrayProvider is properly registered and is found through ProvidersRegistry in Java 6,but not in Java 7. The effect is a consequence of Java bug http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=5041784 which got fixed in Java 7. It can also affect other array entity providers.

Explanation: 

ProvidersRegistry collects the providers for the target type byte[] by checking whether the provider type and the target type are assignable. The corresponding utilities are in GenericsUtils. To determine the provider type, GenericsUtil.getGenericInterfaceParamType retrieves the type from the generic interfaces of ByteArrayProvider. The type parameters in the generic interfaces are represented as java.lang.reflect.Type in Java 6 but as java.lang.Class in Java 7. As consequence, the method GenericsUtils.isAssignableFrom fails to see that the type parameter is an array, hence it returns that byte[] is not assignable to the retrieved type of ByteArrayProvider.

Here is a simple Java program that explains the difference between Java 6 and Java 7. 

In Java 6, the output is:

Type Parameter byte[]
Type Parameter class class sun.reflect.generics.reflectiveObjects.GenericArrayTypeImpl
Is Generic Array true

In Java 7, the output is:

Type Parameter class [B
Type Parameter class class java.lang.Class
Is Generic Array false

------------------------------------------------
{code}
import java.lang.reflect.GenericArrayType;

import java.lang.reflect.ParameterizedType;

import java.lang.reflect.Type;

public class Test
{

  public static void main(String[] args) {
    Class cls = ByteArrayProvider.class;
    Type[] interfaces = cls.getGenericInterfaces();
    for (Type type : interfaces) {
      if (type instanceof ParameterizedType) {
        ParameterizedType pType = (ParameterizedType)type;
        Type t = pType.getActualTypeArguments()[0];
        System.err.println("Type Parameter " + t);
        System.err.println("Type Parameter class " + t.getClass());
        System.err.println("Is Generic Array " + (t instanceof GenericArrayType));
      }
    }
  }
}
{code}

interface MessageBodyWriter<T> { }

class ByteArrayProvider implements MessageBodyWriter<byte[]> { }

-------------------------


I suggest the following fix in GenericsUtils (tested locally in Wink 1.1.3):

{code:title=GenericsUtils.isAssignableFrom|borderStyle=solid}
    public static boolean isAssignableFrom(Type type, Class<?> cls) {
        if (cls.isArray()) {
            if (type instanceof GenericArrayType) {
                GenericArrayType genericArray = (GenericArrayType)type;
                Class<?> componentType = cls.getComponentType();
                return isAssignableFrom(genericArray.getGenericComponentType(), componentType);
            }
            else if ((type instanceof Class<?>) && ((Class<?>)type).isArray()) {
                Class<?> componentType1 = ((Class<?>)type).getComponentType();
                Class<?> componentType2 = cls.getComponentType();
                return isAssignableFrom(componentType1, componentType2);
            }
        } else {
            if (type instanceof GenericArrayType == false) {
                Class<?> classType = getClassType(type, null);
                if (classType == Object.class || classType.isAssignableFrom(cls)) {
                    return true;
                }
            }
        }
        return false;
    }
{code}


    
> Failure to find array entity providers (such as ByteArrayProvider) in Java 7
> ----------------------------------------------------------------------------
>
>                 Key: WINK-363
>                 URL: https://issues.apache.org/jira/browse/WINK-363
>             Project: Wink
>          Issue Type: Bug
>          Components: Providers
>    Affects Versions: 1.1.3
>         Environment: Linux, Java 1.7.0-b147
>            Reporter: Georg Sander
>
> The ByteArrayProvider is properly registered and is found through ProvidersRegistry in Java 6,but not in Java 7. The effect is a consequence of Java bug http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=5041784 which got fixed in Java 7. It can also affect other array entity providers.
> Explanation: 
> ProvidersRegistry collects the providers for the target type byte[] by checking whether the provider type and the target type are assignable. The corresponding utilities are in GenericsUtils. To determine the provider type, GenericsUtil.getGenericInterfaceParamType retrieves the type from the generic interfaces of ByteArrayProvider. The type parameters in the generic interfaces are represented as java.lang.reflect.Type in Java 6 but as java.lang.Class in Java 7. As consequence, the method GenericsUtils.isAssignableFrom fails to see that the type parameter is an array, hence it returns that byte[] is not assignable to the retrieved type of ByteArrayProvider.
> Here is a simple Java program that explains the difference between Java 6 and Java 7. 
> In Java 6, the output is:
> Type Parameter byte[]
> Type Parameter class class sun.reflect.generics.reflectiveObjects.GenericArrayTypeImpl
> Is Generic Array true
> In Java 7, the output is:
> Type Parameter class [B
> Type Parameter class class java.lang.Class
> Is Generic Array false
> {code}
> import java.lang.reflect.GenericArrayType;
> import java.lang.reflect.ParameterizedType;
> import java.lang.reflect.Type;
> public class Test
> {
>   public static void main(String[] args) {
>     Class cls = ByteArrayProvider.class;
>     Type[] interfaces = cls.getGenericInterfaces();
>     for (Type type : interfaces) {
>       if (type instanceof ParameterizedType) {
>         ParameterizedType pType = (ParameterizedType)type;
>         Type t = pType.getActualTypeArguments()[0];
>         System.err.println("Type Parameter " + t);
>         System.err.println("Type Parameter class " + t.getClass());
>         System.err.println("Is Generic Array " + (t instanceof GenericArrayType));
>       }
>     }
>   }
> }
> interface MessageBodyWriter<T> { }
> class ByteArrayProvider implements MessageBodyWriter<byte[]> { }
> {code}
> I suggest the following fix in GenericsUtils (tested locally in Wink 1.1.3):
> {code:title=GenericsUtils.isAssignableFrom|borderStyle=solid}
>     public static boolean isAssignableFrom(Type type, Class<?> cls) {
>         if (cls.isArray()) {
>             if (type instanceof GenericArrayType) {
>                 GenericArrayType genericArray = (GenericArrayType)type;
>                 Class<?> componentType = cls.getComponentType();
>                 return isAssignableFrom(genericArray.getGenericComponentType(), componentType);
>             }
>             else if ((type instanceof Class<?>) && ((Class<?>)type).isArray()) {
>                 Class<?> componentType1 = ((Class<?>)type).getComponentType();
>                 Class<?> componentType2 = cls.getComponentType();
>                 return isAssignableFrom(componentType1, componentType2);
>             }
>         } else {
>             if (type instanceof GenericArrayType == false) {
>                 Class<?> classType = getClassType(type, null);
>                 if (classType == Object.class || classType.isAssignableFrom(cls)) {
>                     return true;
>                 }
>             }
>         }
>         return false;
>     }
> {code}

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Updated] (WINK-363) Failure to find array entity providers (such as ByteArrayProvider) in Java 7

Posted by "Georg Sander (Updated) (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/WINK-363?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Georg Sander updated WINK-363:
------------------------------

    Attachment: GenericsUtils.java

Attached the version I used for debugging, just for the purpose of my granting you license for inclusion. 

If I might have left debug code inside that file, please ignore. I have no clean version at hand right now. Look only at the method isAssignableFrom, that's where the change must go.
                
> Failure to find array entity providers (such as ByteArrayProvider) in Java 7
> ----------------------------------------------------------------------------
>
>                 Key: WINK-363
>                 URL: https://issues.apache.org/jira/browse/WINK-363
>             Project: Wink
>          Issue Type: Bug
>          Components: Providers
>    Affects Versions: 1.1.3
>         Environment: Linux, Java 1.7.0-b147
>            Reporter: Georg Sander
>         Attachments: GenericsUtils.java
>
>
> The ByteArrayProvider is properly registered and is found through ProvidersRegistry in Java 6,but not in Java 7. The effect is a consequence of Java bug http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=5041784 which got fixed in Java 7. It can also affect other array entity providers.
> Explanation: 
> ProvidersRegistry collects the providers for the target type byte[] by checking whether the provider type and the target type are assignable. The corresponding utilities are in GenericsUtils. To determine the provider type, GenericsUtil.getGenericInterfaceParamType retrieves the type from the generic interfaces of ByteArrayProvider. The type parameters in the generic interfaces are represented as java.lang.reflect.Type in Java 6 but as java.lang.Class in Java 7. As consequence, the method GenericsUtils.isAssignableFrom fails to see that the type parameter is an array, hence it returns that byte[] is not assignable to the retrieved type of ByteArrayProvider.
> Here is a simple Java program that explains the difference between Java 6 and Java 7. 
> In Java 6, the output is:
> Type Parameter byte[]
> Type Parameter class class sun.reflect.generics.reflectiveObjects.GenericArrayTypeImpl
> Is Generic Array true
> In Java 7, the output is:
> Type Parameter class [B
> Type Parameter class class java.lang.Class
> Is Generic Array false
> {code}
> import java.lang.reflect.GenericArrayType;
> import java.lang.reflect.ParameterizedType;
> import java.lang.reflect.Type;
> public class Test
> {
>   public static void main(String[] args) {
>     Class cls = ByteArrayProvider.class;
>     Type[] interfaces = cls.getGenericInterfaces();
>     for (Type type : interfaces) {
>       if (type instanceof ParameterizedType) {
>         ParameterizedType pType = (ParameterizedType)type;
>         Type t = pType.getActualTypeArguments()[0];
>         System.err.println("Type Parameter " + t);
>         System.err.println("Type Parameter class " + t.getClass());
>         System.err.println("Is Generic Array " + (t instanceof GenericArrayType));
>       }
>     }
>   }
> }
> interface MessageBodyWriter<T> { }
> class ByteArrayProvider implements MessageBodyWriter<byte[]> { }
> {code}
> I suggest the following fix in GenericsUtils (tested locally in Wink 1.1.3):
> {code:title=GenericsUtils.isAssignableFrom|borderStyle=solid}
>     public static boolean isAssignableFrom(Type type, Class<?> cls) {
>         if (cls.isArray()) {
>             if (type instanceof GenericArrayType) {
>                 GenericArrayType genericArray = (GenericArrayType)type;
>                 Class<?> componentType = cls.getComponentType();
>                 return isAssignableFrom(genericArray.getGenericComponentType(), componentType);
>             }
>             else if ((type instanceof Class<?>) && ((Class<?>)type).isArray()) {
>                 Class<?> componentType1 = ((Class<?>)type).getComponentType();
>                 Class<?> componentType2 = cls.getComponentType();
>                 return isAssignableFrom(componentType1, componentType2);
>             }
>         } else {
>             if (type instanceof GenericArrayType == false) {
>                 Class<?> classType = getClassType(type, null);
>                 if (classType == Object.class || classType.isAssignableFrom(cls)) {
>                     return true;
>                 }
>             }
>         }
>         return false;
>     }
> {code}

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Commented] (WINK-363) Failure to find array entity providers (such as ByteArrayProvider) in Java 7

Posted by "Michael Fiedler (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/WINK-363?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13428287#comment-13428287 ] 

Michael Fiedler commented on WINK-363:
--------------------------------------

[~luciano resende] Sorry, yes, I was asking for a release.  I am a committer on the Eclipse Lyo project [1] and we currently consume Wink for our builds from maven central.   We have array providers for some custom media types and we're currently broken on Java 7 for these providers.

What might be the outlook on a new 1.2.x maint. release?  I'd prefer to go that route vs having to checkin patched Wink source.  Thanks.

Let me know if I should be making this type of request on the mailing list.

[1] - http://eclipse.org/lyo/
                
> Failure to find array entity providers (such as ByteArrayProvider) in Java 7
> ----------------------------------------------------------------------------
>
>                 Key: WINK-363
>                 URL: https://issues.apache.org/jira/browse/WINK-363
>             Project: Wink
>          Issue Type: Bug
>          Components: Providers
>    Affects Versions: 1.2
>         Environment: Linux, Java 1.7.0-b147
>            Reporter: Georg Sander
>             Fix For: 1.3
>
>         Attachments: GenericsUtils.java
>
>
> The ByteArrayProvider is properly registered and is found through ProvidersRegistry in Java 6,but not in Java 7. The effect is a consequence of Java bug http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=5041784 which got fixed in Java 7. It can also affect other array entity providers.
> Explanation: 
> ProvidersRegistry collects the providers for the target type byte[] by checking whether the provider type and the target type are assignable. The corresponding utilities are in GenericsUtils. To determine the provider type, GenericsUtil.getGenericInterfaceParamType retrieves the type from the generic interfaces of ByteArrayProvider. The type parameters in the generic interfaces are represented as java.lang.reflect.Type in Java 6 but as java.lang.Class in Java 7. As consequence, the method GenericsUtils.isAssignableFrom fails to see that the type parameter is an array, hence it returns that byte[] is not assignable to the retrieved type of ByteArrayProvider.
> Here is a simple Java program that explains the difference between Java 6 and Java 7. 
> In Java 6, the output is:
> Type Parameter byte[]
> Type Parameter class class sun.reflect.generics.reflectiveObjects.GenericArrayTypeImpl
> Is Generic Array true
> In Java 7, the output is:
> Type Parameter class [B
> Type Parameter class class java.lang.Class
> Is Generic Array false
> {code}
> import java.lang.reflect.GenericArrayType;
> import java.lang.reflect.ParameterizedType;
> import java.lang.reflect.Type;
> public class Test
> {
>   public static void main(String[] args) {
>     Class cls = ByteArrayProvider.class;
>     Type[] interfaces = cls.getGenericInterfaces();
>     for (Type type : interfaces) {
>       if (type instanceof ParameterizedType) {
>         ParameterizedType pType = (ParameterizedType)type;
>         Type t = pType.getActualTypeArguments()[0];
>         System.err.println("Type Parameter " + t);
>         System.err.println("Type Parameter class " + t.getClass());
>         System.err.println("Is Generic Array " + (t instanceof GenericArrayType));
>       }
>     }
>   }
> }
> interface MessageBodyWriter<T> { }
> class ByteArrayProvider implements MessageBodyWriter<byte[]> { }
> {code}
> I suggest the following fix in GenericsUtils (tested locally in Wink 1.1.3):
> {code:title=GenericsUtils.isAssignableFrom|borderStyle=solid}
>     public static boolean isAssignableFrom(Type type, Class<?> cls) {
>         if (cls.isArray()) {
>             if (type instanceof GenericArrayType) {
>                 GenericArrayType genericArray = (GenericArrayType)type;
>                 Class<?> componentType = cls.getComponentType();
>                 return isAssignableFrom(genericArray.getGenericComponentType(), componentType);
>             }
>             else if ((type instanceof Class<?>) && ((Class<?>)type).isArray()) {
>                 Class<?> componentType1 = ((Class<?>)type).getComponentType();
>                 Class<?> componentType2 = cls.getComponentType();
>                 return isAssignableFrom(componentType1, componentType2);
>             }
>         } else {
>             if (type instanceof GenericArrayType == false) {
>                 Class<?> classType = getClassType(type, null);
>                 if (classType == Object.class || classType.isAssignableFrom(cls)) {
>                     return true;
>                 }
>             }
>         }
>         return false;
>     }
> {code}

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira