Skip to content

Bean Introspection problem under IBM Java 1.6 with new ExtendedBeanInfo [SPR-9453] #14088

Closed

Description

@spring-projects-issues

Friedrich Messner opened SPR-9453 and commented

We're using Spring's BeanWrapper to access a bean via reflection. For one bean's property

  • which has a generic type
  • which is read-only (no setter)
  • whose getter implements an interface

we're getting a org.springframework.beans.NotReadablePropertyException since Spring 3.1. I tracked it a little bit and found out that it is related to the ExtendedBeanInfo class introduced with Spring 3.1. The following example demonstrates this:

package org.springframework.beans;

import static org.junit.Assert.assertEquals;

import java.beans.BeanInfo;
import java.beans.IntrospectionException;
import java.beans.Introspector;

import org.junit.Test;

public class BeanInfoTest {

    public interface Interface<T> {
        T getProp();
    }

    public final class Bean implements Interface<Class<?>> {
        private Class<?> prop;
        public Class<?> getProp() { return prop; }
    }

    @Test
    public void testWithPlainBeanInfo() throws IntrospectionException {
        BeanInfo info = Introspector.getBeanInfo(Bean.class);
        assertEquals(2, info.getPropertyDescriptors().length);
    }

    @Test
    public void testWithExtendedBeanInfo() throws IntrospectionException {
        ExtendedBeanInfo extendedInfo = new ExtendedBeanInfo(
                Introspector.getBeanInfo(Bean.class));
        assertEquals(2, extendedInfo.getPropertyDescriptors().length);
    }
}

While the first test passes, the second fails on IBM JVM 1.6.

If we do any of

  • add a setter
  • remove the interface
  • change the type to non-generic (e.g. String)
  • run it under Sun JVM 1.6

it works.

It seems that ExtendedBeanInfo has a problem with the covariant return types coming from the bridge method for the generic property.


Affects: 3.1.1

Attachments:

Issue Links:

Referenced from: commits b50bb50, 0ee1256, 30d0bd3, 4a8be69

1 votes, 5 watchers

Activity

  1. spring-projects-issues commented on May 30, 2012

    @spring-projects-issues
    CollaboratorAuthor

    Friedrich Messner commented

    Just to clarify: with "generic property" I refer to the <T> in the interface and not to the <?> in the subclass property.

  2. spring-projects-issues commented on Jun 4, 2012

    @spring-projects-issues
    CollaboratorAuthor

    Chris Beams commented

    Thanks, Friedrich. I'll need to get an IBM JDK 6 environment up and running to validate / fix this. If, in the meantime, you're feeling ambitious and would like to attempt a fix yourself, it would be more than welcome! See the contributor guidelines for details.

  3. spring-projects-issues commented on Jul 3, 2012

    @spring-projects-issues
    CollaboratorAuthor

    Dries Schulten commented

    I see the exact same behavior while using the Oracle 1.7 JDK versus the Oracle 1.6 JDK (OS X and Linux). A generic read-only property isn't seen by the extended bean info. The 'normal' bean info finds the property as expected.

    The difference is in the output of the ClassUtils.getMostSpecificMethod
    While running 1.6: returns a method with a interface return type, this matches the method ExtendedBeanInfo is searching for -> success
    While running 1.7: returns a method with the concrete object return type, no match with the method to search -> property not added and thus not found

    I think this is the same issue, but I don't have a IBM JDK 6 to test.

    Attaching a simple Maven test project.

  4. spring-projects-issues commented on Jul 3, 2012

    @spring-projects-issues
    CollaboratorAuthor

    Chris Beams commented

    Thanks, Dries.

  5. spring-projects-issues commented on Aug 15, 2012

    @spring-projects-issues
    CollaboratorAuthor

    Donnchadh O Donnabhain commented

    I'm seeing a similar problem with Sun JDK 1.7.0_u6 on OS X and Spring 3.1.2. It seems to be fine with JDK 1.6.

  6. spring-projects-issues commented on Aug 15, 2012

    @spring-projects-issues
    CollaboratorAuthor

    Donnchadh O Donnabhain commented

    The reason that ClassUtils.getMostSpecificMethod is producing different output appears to be that it is receiving different input. In the above example {Introspector.getBeanInfo} the method with the concrete object return type.

  7. spring-projects-issues commented on Aug 15, 2012

    @spring-projects-issues
    CollaboratorAuthor

    Donnchadh O Donnabhain commented

    The constructor PropertyDescriptor(PropertyDescriptor x, PropertyDescriptor y) which is used by Introspector.processPropertyDescriptors() to merge PropertyDesriptor s has changed between JDK 1.6.0 and JDK 1.7.0

    	// Figure out the merged read method.
    	Method xr = x.getReadMethod();
    	Method yr = y.getReadMethod();
    
    	// Normally give priority to y's readMethod.
    	try {
    	    if (yr != null && yr.getDeclaringClass() == getClass0()) {
    		setReadMethod(yr);
    	    } else {
    		setReadMethod(xr);
    	    }
    	} catch (IntrospectionException ex) {
    	    // fall through
    	}
    
            // Figure out the merged read method.
            Method xr = x.getReadMethod();
            Method yr = y.getReadMethod();
    
            // Normally give priority to y's readMethod.
            try {
                if (isAssignable(xr, yr)) {
                    setReadMethod(yr);
                } else {
                    setReadMethod(xr);
                }
            } catch (IntrospectionException ex) {
                // fall through
            }
    

    The result is that the MethodDescriptor refers to public java.lang.Object org.springframework.beans.BeanInfoTest$Bean.getProp() and the PropertyDescriptor refers to public java.lang.Class org.springframework.beans.BeanInfoTest$Bean.getProp() in the above example. Thus, the property isn't added in the ExtendedBeanInfo constructor.

  8. spring-projects-issues commented on Aug 15, 2012

    @spring-projects-issues
    CollaboratorAuthor

    Chris Beams commented

    Thanks for the detail, Donnchadh. This should help quite a bit.

  9. spring-projects-issues commented on Aug 19, 2012

    @spring-projects-issues
    CollaboratorAuthor

    Chris Beams commented

    See also the repro project submitted in association with #14336 (which has now been resolved as a duplicate of this issue).

  10. spring-projects-issues commented on Aug 22, 2012

    @spring-projects-issues
    CollaboratorAuthor

    Chris Beams commented

    See additional comments at #14336.

  11. spring-projects-issues commented on Sep 9, 2012

    @spring-projects-issues
    CollaboratorAuthor

    Chris Beams commented

    This issue is now resolved with the commit shown below.

    More importantly, with the completion of #14357 ExtendedBeanInfo is now no longer part of the default code path, meaning that even though this regression has been fixed, it would no longer be encountered anyway. Note that #14357 applies only to 3.2 and beyond, whereas the specific fix addressed by this issue will be backported to 3.1.x with #14412.

    commit b50bb5071ac353e77e9d38c72f888de3add923b2
    Author: Chris Beams <[email protected]>
    Commit: Chris Beams <[email protected]>
    
        Address various ExtendedBeanInfo bugs
        
         - Ensure that ExtendedBeanInfoTests succeeds when building under JDK 7
        
         - Improve handling of read and write method registration where
           generic interfaces are involved, per SPR-9453
        
         - Add repro test for SPR-9702, in which EBI fails to register
           an indexed read method under certain circumstances
        
        Issue: SPR-9702, SPR-9414, SPR-9453
    
  12. spring-projects-issues commented on Nov 25, 2012

    @spring-projects-issues
    CollaboratorAuthor

    Chris Beams commented

    A general note to watchers of ExtendedBeanInfo-related issues: #14663 is a major refactoring of ExtendedBeanInfo and overall support for non-void returning setter methods.

    If you have submitted a reproduction project with this issue, we have run it through its paces against these new changes, but we would like to ask you to do the same against your actual applications.

    Please consider updating your dev or test builds to work against 3.1.4.BUILD-SNAPSHOT and/or 3.2.0.BUILD-SNAPSHOT to verify, and we would appreciate any feedback, even if it's to let us know that all is well. So that we can consolidate feedback, please add your comments to #14663, and mention the original issue(s) that you were watching.

    Thanks!

    Note also that testing against 3.1.4 is preferable to 3.2.0 because ExtendedBeanInfo is always in the code path in the latter, while in 3.2.0 we've optimized things such that ExtendedBeanInfo is only in play for bean classes that have one or more non-void returning setter methods.

  13. added
    type: bug
    in: core
    on Jan 11, 2019
  14. added this to the 3.2 M2 milestone on Jan 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    in: coretype: bug

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions