Status/Resolution/Reason: Closed/Fixed/
Reporter/Name(from Bugbase): Bradley Wood / Bradley Wood (Bradley Wood)
Created: 10/22/2014
Components: Language, Java Integration
Versions: 10.0
Failure Type: Cosmetic Issue
Found In Build/Fixed In Build: Final / CF11 Update5,CF10 Update16
Priority/Frequency: Normal / All users will encounter
Locale/System: English / Platforms All
Vote Count: 6
Problem Description:
When creating an instance of a Java class, if any exception is caught, the following message and detail is thrown:
Object instantiation exception
An exception occurred while instantiating a Java object. The class must not be an interface or an abstract class.
I don't mind the message or the first half of the detail as they are accurate and helpful. The issue is with the bit that says "The class must not be an interface or an abstract class.". While that is a true statement, it has never been the issue for me and just seems a bit misleading since it might send devs down the wrong path. I usually encounter this error when a runtime exception is thrown from the java class's constructor.
Perhaps rewording that bit to simply point the dev to the bottom of the stack trace where the "caused by" bits are would be better instead of guessing. I have seen a lot of people confused by this since they think error is telling them they are instantiating a base class or interface..
Another option would be to try to include the original "cause" message, or simply do not catch the error at all if the underlying Java exception is more useful. In some cases, the "caught' error is java.lang.reflect.InvocationTargetException which isn't very useful and the REAL error is two levels deep so that last option may not be as good.
Here's the piece of code I was using today to produce this:
createObject( 'java', 'java.io.FileInputStream' ).init( variables.fileThatDoesNotExist );
Here is the stack trace :
Object instantiation exception.
An exception occurred while instantiating a Java object. The class must not be an interface or an abstract class. Error: ''.
coldfusion.runtime.java.JavaObjectInstantiationException: Object instantiation exception.
at coldfusion.runtime.java.JavaProxy.CreateObject(JavaProxy.java:171)
at coldfusion.runtime.java.JavaProxy.invoke(JavaProxy.java:80)
at coldfusion.runtime.CfJspPage._invoke(CfJspPage.java:2432)
at cfBaseSheet2ecfc1369587804$funcADDLOGO.runFunction(C:\sites\file.cfc:306)
<many lines removed>
at java.lang.Thread.run(Thread.java:722)
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:525)
at coldfusion.runtime.java.JavaProxy.CreateObject(JavaProxy.java:166)
... 169 more
Caused by: java.io.FileNotFoundException: C:\sits\doesnotexist.png (The system cannot find the file specified)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.(FileInputStream.java:138)
at java.io.FileInputStream.(FileInputStream.java:97)
... 174 more
----------------------------- Additional Watson Details -----------------------------
Watson Bug ID: 3842365
External Customer Info:
External Company:
External Customer Name: bradwood.com
External Customer Email:
External Test Config: My Hardware and Environment details:
Attachments:
Comments: