Inline Java in CFML question. I poss need more eye...
# adobe
a
Inline Java in CFML question. I poss need more eyes on this, in case I'm doing something wrong. [I'll put this in a thread, gimme a moment to write-up the code]
This works A-OK:
Copy code
// vendor/ColdFusion/2021/inlineJava/MyCustomExceptionUsingStringMetadata.cfc

component {

    public function create(required string message, required string metadata) {

        var myException = java {


            public class MyException extends java.lang.Exception {

                private String metadata;

                public MyException(String message, String metadata) {
                    super(message);
                    this.metadata = metadata;
                }

                public String getMetadata() {
                    return this.metadata;
                }
            }
        }

       return myException.init(message, metadata)
    }
}
Copy code
<cfscript>
    // vendor/ColdFusion/2021/inlineJava/testMyCustomExceptionUsingStringMetadata.cfm

    import vendor.ColdFusion.2021.inlineJava.MyCustomExceptionUsingStringMetadata;

    metadata = "Zachary Cameron Lynch"

    o = new MyCustomExceptionUsingStringMetadata()

    myCustomException = o.create("Oopsy", metadata)

    writeDump(myCustomException)

    throw(object=myCustomException)
</cfscript>
The relevant bit is that the Exception's
metadata
param is a String.
This errors:
Copy code
// vendor/ColdFusion/2021/inlineJava/MyCustomExceptionUsingStructMetadata.cfc

component {

    public function create(required string message, required struct metadata) {

        var myException = java {
            import coldfusion.runtime.Struct;

            public class MyException extends java.lang.Exception {

                private Struct metadata;

                public MyException(String message, Struct metadata) {
                    super(message);
                    this.metadata = metadata;
                }

                public Struct getMetadata() {
                    return this.metadata;
                }
            }
        }

       return myException.init(message, metadata)
    }
}
Copy code
<cfscript>
    // vendor/ColdFusion/2021/inlineJava/testMyCustomExceptionUsingStructMetadata.cfm

    import vendor.ColdFusion.2021.inlineJava.MyCustomExceptionUsingStructMetadata;

    metadata = {
        firstName = "Zachary",
        lastName = "Cameron Lynch"
    }

    o = new MyCustomExceptionUsingStructMetadata()

    myCustomException = o.create("Oopsy", metadata)

    writeDump(myCustomException)

    throw(object=myCustomException)
</cfscript>
The relevant bit (and only difference) is that the Exception's
metadata
param is a CFML struct.
The error is:
Copy code
Unable to find a constructor for class MyException that accepts parameters of type ( java.lang.String, coldfusion.runtime.Struct ).
Note: it is NOT that it's not "understanding" what a Struct is. It gives as compile error if I don't have
import coldfusion.runtime.Struct
As far as I can tell all this code is analogous, except the first example uses a
java.lang.String
, and the second uses a
coldfusion.runtime.Struct
. Can anyone spot where I'm getting anything wrong?
@Mark Takata (Adobe) could you pls get some technical eyes from the CF Team to have a gander @ this? Cheers fella.
1
@Mark Takata (Adobe) sorry to ping you again on this, but did you actually get any traction with getting one of the CF Devs to look at this?
m
Um, this got escalated to one of the other engineers but I actually think that engineer actually left for a different position inside Adobe. Lemme re-send this to his replacement. Sorry for the delay Adam...
Re-sent & also copied a couple other people so I can get more eyes on it
a
I have this effect on ppl.