Adam Cameron
Adam Cameron
// 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)
}
}
<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.Adam Cameron
// 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)
}
}
<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.Adam Cameron
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?Adam Cameron
Adam Cameron
Mark Takata (Adobe)
06/10/2022, 9:51 PMMark Takata (Adobe)
06/10/2022, 9:56 PMAdam Cameron