JDK-7087876 : java/beans/PropertyDescriptor.html#createPropertyEditor() throws RE if editor cannot be created
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.beans
  • Affected Version: 7
  • Priority: P2
  • Status: Closed
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2011-09-07
  • Updated: 2013-11-11
  • Resolved: 2011-12-14
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 8
8 b17Fixed
Related Reports
Relates :  
Description
JDK : 7
Platform: All

The CCC request http://ccc.sfbay/4274639 introduced a new method in JavaSE 1.5:

http://download.oracle.com/javase/7/docs/api/java/beans/PropertyDescriptor.html#createPropertyEditor%28java.lang.Object%29

The method says:

Returns:
    a property editor instance or null if a property editor has not been defined or cannot be created

However the implmementation throws RuntimeExcetion if the editor has no public constructors for example.

Please see the following code sample:

import java.beans.IntrospectionException;
import java.beans.PropertyDescriptor;
import java.beans.PropertyEditorSupport;

public class CreatePropEd {

    public static void main(String[] args) throws IntrospectionException {
        final PropertyDescriptor descriptor = new PropertyDescriptor("prop1", MyBean.class);
        descriptor.setPropertyEditorClass(PropEd_noPubConstructors.class);
        descriptor.createPropertyEditor(new Object());
    }

    public static class MyBean {
        String prop1;
        public String getProp1() { return prop1; }
        public void setProp1(String prop1) { this.prop1 = prop1;  }
    }

    public static class PropEd_noPubConstructors extends PropertyEditorSupport {
        private PropEd_noPubConstructors() {  }
    }
}


The output willl be

Exception in thread "main" java.lang.RuntimeException: PropertyEditor not instantiated
	at java.beans.PropertyDescriptor.createPropertyEditor(PropertyDescriptor.java:459)
	at bugs.CreatePropEd.main(CreatePropEd.java:12)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:601)
	at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
Caused by: java.lang.IllegalAccessException: Class java.beans.PropertyDescriptor can not access a member of class bugs.CreatePropEd$PropEd_noPubConstructors with modifiers "private"
	at sun.reflect.Reflection.ensureMemberAccess(Reflection.java:95)
	at java.lang.Class.newInstance0(Class.java:366)
	at java.lang.Class.newInstance(Class.java:325)
	at java.beans.PropertyDescriptor.createPropertyEditor

Comments
Verified in jdk8b115 Windows 7 x64 java version "1.8.0-ea" Java(TM) SE Runtime Environment (build 1.8.0-ea-b115) Java HotSpot(TM) 64-Bit Server VM (build 25.0-b57, mixed mode) Test CreatePropEd from description passed sucessful
11-11-2013

EVALUATION We should return null as specified.
08-09-2011