Skip to content

Couple of ExtendedBeanInfoTests failing on Java 7 [SPR-9007] #13646

Closed

Description

@spring-projects-issues

Stevo Slavić opened SPR-9007 and commented

ExtendedBeanInfoTests.reproSpr8522 and some other tests fail when run with Java 7 (openjdk & oracle).

[junit] Testcase: reproSpr8522(org.springframework.beans.ExtendedBeanInfoTests):    FAILED
[junit] 
[junit] Expected: is <true>
[junit]      got: <false>
[junit] 
[junit] junit.framework.AssertionFailedError: 
[junit] Expected: is <true>
[junit]      got: <false>
[junit] 
[junit]     at org.springframework.beans.ExtendedBeanInfoTests.reproSpr8522(ExtendedBeanInfoTests.java:553)
[junit] 
[junit] 
[junit] Testcase: indexedReadAndNonStandardIndexedWrite(org.springframework.beans.ExtendedBeanInfoTests):   FAILED
[junit] 
[junit] Expected: is <true>
[junit]      got: <false>
[junit] 
[junit] junit.framework.AssertionFailedError: 
[junit] Expected: is <true>
[junit]      got: <false>
[junit] 
[junit]     at org.springframework.beans.ExtendedBeanInfoTests.indexedReadAndNonStandardIndexedWrite(ExtendedBeanInfoTests.java:436)
[junit] 
[junit] 
[junit] Testcase: indexedReadAndNonStandardWriteAndNonStandardIndexedWrite(org.springframework.beans.ExtendedBeanInfoTests):        FAILED
[junit] 
[junit] Expected: is <true>
[junit]      got: <false>
[junit] 
[junit] junit.framework.AssertionFailedError: 
[junit] Expected: is <true>
[junit]      got: <false>
[junit] 
[junit]     at org.springframework.beans.ExtendedBeanInfoTests.indexedReadAndNonStandardWriteAndNonStandardIndexedWrite(ExtendedBeanInfoTests.java:459)

Tests pass when run using Java 6 (openjdk). Looking at the source of Introspector, in getTargetPropertyInfo at least following has been changed:

from

} else if (argCount == 2) {
        if (argTypes[0] == int.class && name.startsWith(SET_PREFIX)) {
        pd = new IndexedPropertyDescriptor(this.beanClass, name.substring(3), null, null, null, method);
        if (throwsException(method, PropertyVetoException.class)) {
            pd.setConstrained(true);
        }
    }
}

to

} else if (argCount == 2) {
        if (void.class.equals(resultType) && int.class.equals(argTypes[0]) && name.startsWith(SET_PREFIX)) {
        pd = new IndexedPropertyDescriptor(this.beanClass, name.substring(3), null, null, null, method);
        if (throwsException(method, PropertyVetoException.class)) {
            pd.setConstrained(true);
        }
    }
}

It seems that non-standard indexed write methods like

public Object setFoos(int i, String foo) { return new Object(); }

are no longer supported - method has to return void.
After changing these setters to return void, tests would pass on both Java 6 and Java 7.


Affects: 3.1 GA

Issue Links:

Referenced from: commits 4a8be69, 0ee1256

Activity

  1. spring-projects-issues commented on Feb 13, 2012

    @spring-projects-issues
    CollaboratorAuthor

    Chris Beams commented

    commit 0a5392e37d268d4df9526216531a6655e52b9f38
    Author: Chris Beams <[email protected]>
    Date:   Mon Feb 13 13:51:14 2012 +0100
    
        Compensate for changes in JDK 7 Introspector
        
        Prior to JDK 7, java.beans.Introspector registered indexed write methods
        irrespective of return type, for example either of the following methods
        were legal
        
            void setFoo(int i, Foo foo)
            Object setFoo(int i, Foo foo)
        
        This was considered a bug and disallowed starting with JDK 7, such that
        only the former signature is a candidate.
        
        Supporting non-void returning setter methods is exactly what
        ExtendedBeanInfo was designed to do, and prior to this commit, the
        implementation of ExtendedBeanInfo assumed this (somewhat surprising)
        behavior from the underlying Introspector, and because it worked out of
        the box, took no extra steps to recognize and register these methods.
        For this reason, non-void returning indexed write methods were not
        registered under JDK 7+, causing test failures in ExtendedBeanInfoTests.
        
        Now the implementation is careful to detect these methods without any
        assumption about Introspector behavior, such that they are registered in
        exactly the same fashion across JDK versions.
        
        Issue: SPR-9014
    
    Notes:
        Issue: SPR-9007 (not SPR-9014)
    
  2. 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.

  3. added
    type: enhancement
    in: core
    on Jan 11, 2019
  4. added this to the 3.1.1 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: enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions