tracker issue : CF-3842365

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

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 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', '' ).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: ''. Object instantiation exception.
	at coldfusion.runtime.CfJspPage._invoke(
	at cfBaseSheet2ecfc1369587804$funcADDLOGO.runFunction(C:\sites\file.cfc:306)

<many lines removed>

Caused by: java.lang.reflect.InvocationTargetException
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(
	at java.lang.reflect.Constructor.newInstance(
	... 169 more
Caused by: C:\sits\doesnotexist.png (The system cannot find the file specified)
	at Method)
	... 174 more

----------------------------- Additional Watson Details -----------------------------

Watson Bug ID:	3842365

External Customer Info:
External Company:  
External Customer Name:
External Customer Email:  
External Test Config: My Hardware and Environment details:



Note, I just tested the same code on Railo 4.2.1. <cfset createObject( 'java', '' ).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: notafile (The system cannot find the file specified) at Method):-2 at Source):-1 at 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( at railo.runtime.reflection.Reflector.callConstructor( at at at at railo.runtime.util.VariableUtilImpl.callFunctionWithoutNamedValues( at railo.runtime.PageContextImpl.getFunction( at index_cfm$ 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 Thanks!, -Aaron
Comment by External U.
10518 | November 20, 2015 04:08:35 AM GMT