java class method not found

Description

When trying to access a java method we get the error: Error getting method ex for class redis.clients.jedis.params.SetParams -

If I dump the object

writeDump(SetParams);

It doesn’t contain the expected methods hence the error - I have no idea what boxlang thinks it is though.

Using CF 2021 to dump the same object we see the expected methods:

my Application.cfc looks like this:

Attachments

3

Activity

Show:

Brad WoodOctober 24, 2024 at 10:18 PM

This repro case can be made much more simply like so

just using a JDK class.

Luis MajanoOctober 24, 2024 at 8:37 PM

Brad will tackle this one. We will follow suite with the no-arg constructor.

Brad WoodOctober 24, 2024 at 5:56 PM

Yes, we need to be auto-calling the no-arg constructor, if found, when an instance method is called on a class. I pointed this out internally a few months ago. This is a documented feature of CF and quite simple.

Not really. Imagine if a class has 5 constructors. Which one would you call?

The no arg one As documented.

What if it doesn’t have ANY constructors?

CF errors, which is reasonable.

Will Adobe/Lucee call the constructor twice

No, they would not. The constructor is not called when the class is loaded, it’s called when and if you call an instance method but don’t have n instance. So basically, our dynamic object needs to detect if there is no targetInstance and the method being called is an instance method, and create the instance via the no-arg constructor on the fly like CF does.

Luis MajanoOctober 24, 2024 at 3:01 PM

Not really. Imagine if a class has 5 constructors. Which one would you call? What if it doesn’t have ANY constructors?
In reality, the concept of instantiating a class is not the same as creating an object proxy.

 

If you would have used new redis.clients.jedis.params.SetParams() Then the constructor is called, which one, it will match the arguments you sent to it. However, since in ACF/LUCEE, you can do what I just did of using the new operator in java classes.

Anyways, this is something to discuss if we want to venture into auto-calling the no-arg constructor or not. It’s also bad practice, because what happens if you do this:

Will Adobe/Lucee call the constructor twice

Doug CainOctober 24, 2024 at 2:38 PM
Edited

I was under the impression that init is always implicitly called when creating an object (in ACF anyway), I guess if you wanted that behaviour it would be better placed as a call to init in the constructor. But I guess ACF just goes right ahead and calls it anyway

Fixed
Pinned fields
Click on the next to a field label to start pinning.

Details

Assignee

Reporter

Fix versions

Priority

Sentry

Created October 24, 2024 at 10:21 AM
Updated October 24, 2024 at 10:35 PM
Resolved October 24, 2024 at 10:35 PM