Bill Brock
01/02/2024, 7:08 PMAdam Cameron
o = new com.example.someapp.somepackage.SomeThing(), and SomeThing.cfc has extends=SomeOtherThing, and SomeOtherThing.cfc is also in com.example.someapp.somepackage ?James Harris
01/03/2024, 1:29 PMextends="SomeOtherThing" is not on the SomeThing component, we can instantiate SomeThing successfully. If the extends is there, however, the failure can occur, and the instantiation of SomeThing ends up failing.Adam Cameron
o = new com.example.someapp.somepackage.SomeOtherThing() works OK? I've seen unexpected errors when trying to extended a CFC that won't compile.James Harris
01/03/2024, 5:24 PMJames Harris
01/09/2024, 6:21 PMDirectory structure
Web Root
Applications
Application1
lib
components
SomeThing.cfc
SomeOtherThing.cfc
Application.cfc
Application2
...
URL rewriting rule to send traffic to Application1 or Application2 as appropriate
SomeThing.cfc
component extends="SomeOtherThing" {
public function init() {}
}
Instantiating SomeThing.cfc via CreateObject("component", "lib.components.SomeThing") or new lib.components.SomeThing() results in the following error:
Detail: Ensure that the name is correct and that the component or interface exists.
Message: Could not find the ColdFusion component or interface lib.components.SomeOtherThing
Observations
• The issue appears to be related to ColdFusion getting confused on path resolution to the extended component.
Additional notes
• We are able to create an object of SomeOtherThing.cfc directly without issue. The problem only occurs when another component is extending it.
• We confirmed that SomeThing.cfc, when not extending SomeOtherThing, is able to create instances of SomeOtherThing using CreateObject() with the following paths: (These tests were just to verify that ColdFusion could find the component once it was within SomeThing).
◦ SomeOtherThing
◦ lib.components.SomeOtherThing
◦ applications.Application1.lib.components.SomeOtherThing
• The issue often goes away by turning on Trusted Cache (which is of course not viable for a development, and sometimes testing platform), but comes back when Trusted Cache is turned back off.
• If ColdFusion does eventually figure out the extends correctly, it will remember it until the server/service is restarted.
Resolution
Use an application specific mapping in Application.cfc to the `lib` directory as such:
this.mappings = {
"/lib" = ExpandPath("./lib")
};bkbk
01/12/2024, 1:24 PMSomeThing.cfc
component extends="applications.Application1.lib.components.SomeOtherThing" {
public function init() {}
}James Harris
01/12/2024, 1:31 PMSomeOtherThing, lib.components.SomeOtherThing, and applications.Application1.lib.components.SomeOtherThing for the extends value. None of them worked, unfortunately.