Title:
References to Java objects extending 'Map' interface don't work with integer keys
| View in TrackerStatus/Resolution/Reason: Closed/Fixed/Fixed
Reporter/Name(from Bugbase): Tim P. / ()
Created: 04/12/2019
Components: Language, Java Integration
Versions: 2018
Failure Type: Crash
Found In Build/Fixed In Build: ColdFusion 2018,0,03,314033 / CF2018U5
Priority/Frequency: Critical / Some users will encounter
Locale/System: ALL / Win All
Vote Count: 3
Problem Description: in all previous CF versions, a Java object which extends the 'Map' interface could be reliably referenced from CF in the same way a CF-created (using StructNew()) struct is. This appears to have changed in the 2018 release
Steps to Reproduce: run the following code:
foo = CreateObject("java","java.util.TreeMap").init(); // this works if you use StructNew() here
i = 1;
foo[i] = "hello #Now()#";
WriteOutput(foo[i]);
Actual Result: crash:
Cannot index into class java.util.TreeMap with index 1 of type class java.lang.Integer.
StackTrace coldfusion.runtime.ArrayNotIndexableException: Cannot index into class java.util.TreeMap with index 1 of type class java.lang.Integer.
at coldfusion.runtime.CfJspPage.ArrayGetAt(CfJspPage.java:1192)
at coldfusion.runtime.CfJspPage._arrayGetAt(CfJspPage.java:1403)
at coldfusion.runtime.CfJspPage._arrayGetAt(CfJspPage.java:1398)
at coldfusion.runtime.CfJspPage._arrayGetAt(CfJspPage.java:932)
at coldfusion.runtime.CfJspPage._arrayGetAt(CfJspPage.java:916)
at cf28ea24ef2dce1d2d4f8c2d9f9b2d467a3f6eb30d2ecfm1790102911.runPage(...)
.
'arrayGetAt' is the problem here - 'foo' is not an array - it appears that the logic is determining the access methods for 'foo' based on the type of 'i' instead of on the type of 'foo'
Expected Result: (no error)
Any Workarounds: update the reference in the WriteOutput to use JavaCast:
WriteOutput(foo[JavaCast("string",i)]);
Attachments:
Comments: