Compat expectations?

I just chucked this into a test I was writing:

myDate = new java("java.sql.Date").valueOf("2011-03-24")

This would work fine on CF; not supported yet on Lucee. I have the isAdobe compat setting switched on (I have both switched on… see other post on that…).

Repro on trycf.com: TryCF.com

If I have isAdobe switched on, I would expect BoxLang’s CFML support to support CF’s functionality, right?

I’m guessing you’ve not got around to implementing this bit yet, so I’ll go back to createObject, but thought I’d let you know anyhow. Also perhaps would be good to get expectations around this managed too.

Cheers.

Looks like the java() BIF just got completleyk overlooked. It’s not even on our spreadsheet:

I think @lmajano may have used Lucee’s BIF that lists all BIFs so that may be why we didn’t get it in the list since Lucee doesn’t have that BIF.

As far as BL, I’m not sure it makes a great deal of sense as we’ve improved our Java interop to just allow

myDate = new java:java.sql.Date()

but I think it makes sense to add it to the compat module as it’s just a passthrough to createObject I think-- for the life of me I can’t actually find it on Adobe’s docs. Not in the alphabetical list of functions. Not in the search. Not in Google. Not in cfdocs. Does this BIF even exist?? lol

I didn’t even know Adobe added that. Anyways, that looks like a simple BIF to add to the compat module. Ticket please

https://ortussolutions.atlassian.net/browse/BL-306

1 Like

Just for reference it was added in ACF 2018
https://helpx.adobe.com/uk/coldfusion/using/whats-new-coldfusion-2018.html#new

To be completely honest, I don’t know how I knew about it either. Probs the “what’s new” doc you pointed to, and testing it on the PR programme. The last version of CF I used was CF9! :wink:

I’ve chased them to document it properly (see the Documentation channel on the CFML Slack).

Glancing at this again, I guess it’s not really even a BIF. I actually wonder if Adobe just added some more globally registered CFCs like Query, HTTP, and StoredProc that just wrap up some logic.

new java( args )

looks like it’s just creating a CFC instance like

new http( args )

They’d have to be returning a custom value from their init() constructor though as it appears to directly return the instance, which is really odd, but CF allows random things to be returned from the init.

Hmm, glancing in the WEB-INF\cfusion\CustomTags\com\adobe\coldfusion folder of a 2023 install (where the http.cfc ftp.cfc, query.cfc, etc) are stored, I don’t see a component.cfc or a java.cfc which makes me think they actually added this as some sort of custom parser thing. Ugh, now I hate it even more, lol.

As far as BL goes, I only care about this for compat-- I’m tempted to actually just handle this in the CF transpiler. Perhaps I can just transpile

 new java("java.lang.String")

to

new java:java.lang.String()

And

new component("path/to/president.cfc")

to

new path.to.president()

I’m really unclear on whether the new syntax allows arguments. There are no docs outside of the link above, which only has very simple use cases.

Oh yeah I didn’t even notice the new being there! Ha.

Best I also revise my suggestion of where Adobe should document this… I’d suggested putting it in the functions part of the CFML reference.

Just as an FYI, the following works (on cf2021):

x = "java.lang.String";
y = new java(x).init("foo");
writeoutput(y);

(I couldn’t get it to work on cf2023 on trycf, hence trying cf2021)

I pinged Abram a few days ago about 2023, but I don’t think he’s been on Slack in a while.

I did some more testing too and it seems, for Java classes anyway, the new java() returns a java proxy object. You can call init() on it, or if you call an instance method, will will call the public no-arg constructor if exists, or error.

So if I did transpile that, it would need to be to

createObject( "java", "java.lang.String" )

to have the equivalent behavior. What’s even more interesting is this code

new java( "java.lang.String", "test" )

throws the error

java.lang.RuntimeException: Jar not found in repository : test:null 
at coldfusion.server.felix.FelixUtil.createObjectFromSingleJar(FelixUtil.java:6231) 
at coldfusion.runtime.CFPage._CreateObject(CFPage.java:10492) 
at coldfusion.runtime.CFPage.CreateObject(CFPage.java:10454) 
at cfmain17198739532272d80e731602dc3a22d8bfd2d11b32d72f28b7f2fa42ecfm1023014540.runPage(651F42E1-D2D7-3064-8128AAD031867116:3) at

which tells me

  • they are delegating to createobject under the hood-- in fact, the compiled bytecode just seems to call createobject directly
  • There are other supported parameters allowed that don’t seem to be documented anywhere. I wonder if the args are just positionally dropped into the createobject BIF in the order presented.

The code

new java( "java.lang.String", "test", "too", "many", "args", "here" )

throws the error

Parameter validation error for the CREATEOBJECT function.

so it’s literally just passing the args along and inserting/defaulting the first parameter to that BIF.

1 Like

FYI, [BL-306] - Welcome is resolved now.