tracker issue : CF-3842365

select a category, or use search below
(searches all categories and all time range)
Title:

Error when instantiation a Java object is misleading

| View in Tracker

Status/Resolution/Reason: Closed/Fixed/

Reporter/Name(from Bugbase): Bradley Wood / Bradley Wood (Bradley Wood)

Created: 10/22/2014

Components: 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

Listed in the version 11.0.05.293506 Issues Fixed doc
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:

Note, I just tested the same code on Railo 4.2.1. <cfset createObject( 'java', 'java.io.FileInputStream' ).init( 'notafile' )> It basically just bubbles the original Java exception right up with no hinting at any underlying reflection, etc. message: notafile (The system cannot find the file specified) cause: java.io.FileNotFoundException notafile (The system cannot find the file specified) at java.io.FileInputStream.open(Native Method):-2 at java.io.FileInputStream.(Unknown Source):-1 at java.io.FileInputStream.(Unknown Source):-1 at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method):-2 at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source):-1 at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source):-1 at java.lang.reflect.Constructor.newInstance(Unknown Source):-1 at railo.runtime.reflection.pairs.ConstructorInstance.invoke(ConstructorInstance.java:34):34 at railo.runtime.reflection.Reflector.callConstructor(Reflector.java:791):791 at railo.runtime.java.JavaObject.init(JavaObject.java:274):274 at railo.runtime.java.JavaObject.call(JavaObject.java:204):204 at railo.runtime.java.JavaObject.call(JavaObject.java:238):238 at railo.runtime.util.VariableUtilImpl.callFunctionWithoutNamedValues(VariableUtilImpl.java:724):724 at railo.runtime.PageContextImpl.getFunction(PageContextImpl.java:1554):1554 at index_cfm$cf.call(/index.cfm:1):1 etc... This behavior is perfect. I don't even have to look for the original message.
Comment by External U.
10516 | October 22, 2014 04:34:11 PM GMT
+1, the existing error message is poor as it's almost always not the issue. If Railo can bubble-back the actual problem, so can ColdFusion
Vote by External U.
10519 | October 23, 2014 12:22:40 PM GMT
Agree with Brad that the current error reporting is pretty unhelpful.
Vote by External U.
10520 | October 23, 2014 12:32:30 PM GMT
Better error reporting is, well, better. This should be a no-brainer.
Vote by External U.
10521 | October 23, 2014 03:02:28 PM GMT
Yup. Make our lives easier, please.
Vote by External U.
10522 | October 23, 2014 07:07:10 PM GMT
.........................
Vote by External U.
10523 | October 23, 2014 11:26:57 PM GMT
+1 ......................
Vote by External U.
10524 | November 26, 2014 02:42:13 AM GMT
The fix for this bug is available in the pre-release build of ColdFusion 11 Update 5 and ColdFusion 10 Update 16
Comment by CFwatson U.
10517 | February 20, 2015 09:25:55 AM GMT
Verified this is fixed in CF11 Update 5 (build 11,0,05,293506). The code in the description now throws java.io.FileNotFoundException. Thanks!, -Aaron
Comment by External U.
10518 | November 20, 2015 04:08:35 AM GMT