Still trying to use NB annotations to declare a singleton action class, this is
driving me nuts...
I did some tests. Calling Actions.forID(x, y) twice in a row returns the same
instance. Same for Utilities.actionsForPath(). Same in my app.
BUT, if I run the second call to Actions.forID(x,y) a few seconds later in my
app (I trigger it manually with the mouse) then, *sometimes* (1/3?), I get a
new instance ! Same problem for Utilities.actionsForPath(). Note that both
calls are done on the EDT.
I looked at the NB code on github, the underlying lookup mechanism in
filesystem/RecognizeInstanceFiles.java is based on ProxyLookup, which uses lazy
instanciation. So I assume that sometimes something happens differently here.
But can not understand why...
I noticed that Actions.forID() uses FileUtil.getFileObject(). Doc says "In
environment with multiple contextual Lookups, the method may return different
FileObject depending on what Lookup serves the executing thread." And
recommends to use FileUtil.getSystemFileObject() to make sure to get a single
instance. What is a "contextual lookup" here ? I guess I have to try recoding
forID() with getSystemFileObject...
Jerome
On 2025/10/02 21:17:20 Jerome Lelasseux wrote: Hi,
I have an action with a no-arg constructor :
@ActionID(category = "jjazz", id = "myactionid")
@ActionRegistration(displayName = "not_used", lazy = false)
@ActionReference(path = "Actions/popupmenu", position = 100)public class
MyAction extends AbstractAction........
In my code an instance is first created using Actions.forId("jjazz",
"myactionid")
I also want to use MyAction in a popup menu. I use
Utilities.actionsForPath("Actions/popupmenu") to retrieve the actions before
creating the popupmenu. But actionsForPath() creates a new instance of
MyAction. Why ?
I'm pretty sure in other cases it reuses the initial instance. Tried to debug
but it does not work inside actionsForPath() -don't know why...
Any tip welcome, thanks.
Jerome