René's URL Explorer Experiment


Title: Commands get instantiated multiple times per run · Issue #476 · scijava/scijava-common · GitHub

Open Graph Title: Commands get instantiated multiple times per run · Issue #476 · scijava/scijava-common

X Title: Commands get instantiated multiple times per run · Issue #476 · scijava/scijava-common

Description: As discussed in this Zulip thread, when invoking a SciJava Command plugin, multiple instances of the command might get instantiated and then thrown away, just to retrieve default parameter values. This can create confusion if there is ac...

Open Graph Description: As discussed in this Zulip thread, when invoking a SciJava Command plugin, multiple instances of the command might get instantiated and then thrown away, just to retrieve default parameter values. ...

X Description: As discussed in this Zulip thread, when invoking a SciJava Command plugin, multiple instances of the command might get instantiated and then thrown away, just to retrieve default parameter values. ...

Opengraph URL: https://github.com/scijava/scijava-common/issues/476

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Commands get instantiated multiple times per run","articleBody":"As discussed in [this Zulip thread](https://imagesc.zulipchat.com/#narrow/stream/327495-scenery.2Bsciview/topic/Class.20initialization.20in.20Add.20commands), when invoking a SciJava `Command` plugin, multiple instances of the command might get instantiated and then thrown away, just to [retrieve default parameter values](https://github.com/scijava/scijava-common/blob/scijava-common-2.98.0/src/main/java/org/scijava/command/CommandModuleItem.java#L168). This can create confusion if there is actual business logic that gets executed during object construction, because it will then be executed multiple times, and if there are side effects, and/or performance implications, they will occur repeatedly.\r\n\r\n\u003cdetails\u003e\u003csummary\u003eStack trace illustrating the multiple instantiations\u003c/summary\u003e\r\n\r\n```\r\nBreakpoint reached at sc.iview.commands.add.AddBox.\u003cinit\u003e(AddBox.kt:75)\r\nBreakpoint reached\r\n    at sc.iview.commands.add.AddBox.\u003cinit\u003e(AddBox.kt:75)\r\n    at java.lang.invoke.DirectMethodHandle$Holder.newInvokeSpecial(DirectMethodHandle$Holder:-1)\r\n    at java.lang.invoke.Invokers$Holder.invokeExact_MT(Invokers$Holder:-1)\r\n    at jdk.internal.reflect.DirectConstructorHandleAccessor.invokeImpl(DirectConstructorHandleAccessor.java:86)\r\n    at jdk.internal.reflect.DirectConstructorHandleAccessor.newInstance(DirectConstructorHandleAccessor.java:62)\r\n    at java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:502)\r\n    at java.lang.reflect.ReflectAccess.newInstance(ReflectAccess.java:128)\r\n    at jdk.internal.reflect.ReflectionFactory.newInstance(ReflectionFactory.java:304)\r\n    at java.lang.Class.newInstance(Class.java:725)\r\n    at org.scijava.plugin.PluginInfo.createInstance(PluginInfo.java:304)\r\n    at org.scijava.command.CommandInfo.createInstance(CommandInfo.java:248)\r\n    at org.scijava.command.CommandModule.instantiateCommand(CommandModule.java:248)\r\n    at org.scijava.command.CommandModule.\u003cinit\u003e(CommandModule.java:98)\r\n    at org.scijava.command.CommandInfo.createModule(CommandInfo.java:326)\r\n    at org.scijava.module.DefaultModuleService.createModule(DefaultModuleService.java:167)\r\n    at org.scijava.module.DefaultModuleService.run(DefaultModuleService.java:206)\r\n    at org.scijava.module.DefaultModuleService.run(DefaultModuleService.java:197)\r\n    at org.scijava.module.DefaultModuleService.run(DefaultModuleService.java:182)\r\n    at org.scijava.menu.ShadowMenu.run(ShadowMenu.java:335)\r\n    at org.scijava.ui.swing.menu.AbstractSwingMenuCreator$1.actionPerformed(AbstractSwingMenuCreator.java:169)\r\n...\r\nnow have 1 CountyThingies\r\nBreakpoint reached at sc.iview.commands.add.AddBox.\u003cinit\u003e(AddBox.kt:75)\r\nBreakpoint reached\r\n    at sc.iview.commands.add.AddBox.\u003cinit\u003e(AddBox.kt:75)\r\n    at java.lang.invoke.DirectMethodHandle$Holder.newInvokeSpecial(DirectMethodHandle$Holder:-1)\r\n    at java.lang.invoke.Invokers$Holder.invokeExact_MT(Invokers$Holder:-1)\r\n    at jdk.internal.reflect.DirectConstructorHandleAccessor.invokeImpl(DirectConstructorHandleAccessor.java:86)\r\n    at jdk.internal.reflect.DirectConstructorHandleAccessor.newInstance(DirectConstructorHandleAccessor.java:62)\r\n    at java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:502)\r\n    at java.lang.reflect.ReflectAccess.newInstance(ReflectAccess.java:128)\r\n    at jdk.internal.reflect.ReflectionFactory.newInstance(ReflectionFactory.java:304)\r\n    at java.lang.Class.newInstance(Class.java:725)\r\n    at org.scijava.command.CommandModuleItem.getDefaultValue(CommandModuleItem.java:168)\r\n    at org.scijava.module.DefaultModuleService.getDefaultValue(DefaultModuleService.java:321)\r\n    at org.scijava.module.process.DefaultValuePreprocessor.assignDefaultValue(DefaultValuePreprocessor.java:76)\r\n    at org.scijava.module.process.DefaultValuePreprocessor.process(DefaultValuePreprocessor.java:61)\r\n    at org.scijava.module.ModuleRunner.preProcess(ModuleRunner.java:103)\r\n    at org.scijava.module.ModuleRunner.run(ModuleRunner.java:154)\r\n    at org.scijava.module.ModuleRunner.call(ModuleRunner.java:125)\r\n    at org.scijava.module.ModuleRunner.call(ModuleRunner.java:64)\r\n    at org.scijava.thread.DefaultThreadService.lambda$wrap$2(DefaultThreadService.java:247)\r\n    at org.scijava.thread.DefaultThreadService$$Lambda/0x0000000800f2ac68.call(Unknown Source:-1)\r\n    at java.util.concurrent.FutureTask.run$$$capture(FutureTask.java:317)\r\n    at java.util.concurrent.FutureTask.run(FutureTask.java:-1)\r\n    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1144)\r\n    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:642)\r\n    at java.lang.Thread.runWith(Thread.java:1596)\r\n    at java.lang.Thread.run(Thread.java:1583)\r\nnow have 2 CountyThingies\r\nBreakpoint reached at sc.iview.commands.add.AddBox.\u003cinit\u003e(AddBox.kt:75)\r\nBreakpoint reached\r\n    at sc.iview.commands.add.AddBox.\u003cinit\u003e(AddBox.kt:75)\r\n    at java.lang.invoke.DirectMethodHandle$Holder.newInvokeSpecial(DirectMethodHandle$Holder:-1)\r\n    at java.lang.invoke.Invokers$Holder.invokeExact_MT(Invokers$Holder:-1)\r\n    at jdk.internal.reflect.DirectConstructorHandleAccessor.invokeImpl(DirectConstructorHandleAccessor.java:86)\r\n    at jdk.internal.reflect.DirectConstructorHandleAccessor.newInstance(DirectConstructorHandleAccessor.java:62)\r\n    at java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:502)\r\n    at java.lang.reflect.ReflectAccess.newInstance(ReflectAccess.java:128)\r\n    at jdk.internal.reflect.ReflectionFactory.newInstance(ReflectionFactory.java:304)\r\n    at java.lang.Class.newInstance(Class.java:725)\r\n    at org.scijava.command.CommandModuleItem.getDefaultValue(CommandModuleItem.java:168)\r\n    at org.scijava.module.DefaultModuleService.getDefaultValue(DefaultModuleService.java:321)\r\n    at org.scijava.module.process.DefaultValuePreprocessor.assignDefaultValue(DefaultValuePreprocessor.java:76)\r\n    at org.scijava.module.process.DefaultValuePreprocessor.process(DefaultValuePreprocessor.java:61)\r\n    at org.scijava.module.ModuleRunner.preProcess(ModuleRunner.java:103)\r\n    at org.scijava.module.ModuleRunner.run(ModuleRunner.java:154)\r\n    at org.scijava.module.ModuleRunner.call(ModuleRunner.java:125)\r\n    at org.scijava.module.ModuleRunner.call(ModuleRunner.java:64)\r\n    at org.scijava.thread.DefaultThreadService.lambda$wrap$2(DefaultThreadService.java:247)\r\n    at org.scijava.thread.DefaultThreadService$$Lambda/0x0000000800f2ac68.call(Unknown Source:-1)\r\n    at java.util.concurrent.FutureTask.run$$$capture(FutureTask.java:317)\r\n    at java.util.concurrent.FutureTask.run(FutureTask.java:-1)\r\n    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1144)\r\n    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:642)\r\n    at java.lang.Thread.runWith(Thread.java:1596)\r\n    at java.lang.Thread.run(Thread.java:1583)\r\nnow have 3 CountyThingies\r\nBreakpoint reached at sc.iview.commands.add.AddBox.\u003cinit\u003e(AddBox.kt:75)\r\nBreakpoint reached\r\n    at sc.iview.commands.add.AddBox.\u003cinit\u003e(AddBox.kt:75)\r\n    at java.lang.invoke.DirectMethodHandle$Holder.newInvokeSpecial(DirectMethodHandle$Holder:-1)\r\n    at java.lang.invoke.Invokers$Holder.invokeExact_MT(Invokers$Holder:-1)\r\n    at jdk.internal.reflect.DirectConstructorHandleAccessor.invokeImpl(DirectConstructorHandleAccessor.java:86)\r\n    at jdk.internal.reflect.DirectConstructorHandleAccessor.newInstance(DirectConstructorHandleAccessor.java:62)\r\n    at java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:502)\r\n    at java.lang.reflect.ReflectAccess.newInstance(ReflectAccess.java:128)\r\n    at jdk.internal.reflect.ReflectionFactory.newInstance(ReflectionFactory.java:304)\r\n    at java.lang.Class.newInstance(Class.java:725)\r\n    at org.scijava.command.CommandModuleItem.getDefaultValue(CommandModuleItem.java:168)\r\n    at org.scijava.module.DefaultModuleService.getDefaultValue(DefaultModuleService.java:321)\r\n    at org.scijava.module.process.DefaultValuePreprocessor.assignDefaultValue(DefaultValuePreprocessor.java:76)\r\n    at org.scijava.module.process.DefaultValuePreprocessor.process(DefaultValuePreprocessor.java:61)\r\n    at org.scijava.module.ModuleRunner.preProcess(ModuleRunner.java:103)\r\n    at org.scijava.module.ModuleRunner.run(ModuleRunner.java:154)\r\n    at org.scijava.module.ModuleRunner.call(ModuleRunner.java:125)\r\n    at org.scijava.module.ModuleRunner.call(ModuleRunner.java:64)\r\n    at org.scijava.thread.DefaultThreadService.lambda$wrap$2(DefaultThreadService.java:247)\r\n    at org.scijava.thread.DefaultThreadService$$Lambda/0x0000000800f2ac68.call(Unknown Source:-1)\r\n    at java.util.concurrent.FutureTask.run$$$capture(FutureTask.java:317)\r\n    at java.util.concurrent.FutureTask.run(FutureTask.java:-1)\r\n    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1144)\r\n    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:642)\r\n    at java.lang.Thread.runWith(Thread.java:1596)\r\n    at java.lang.Thread.run(Thread.java:1583)\r\nnow have 4 CountyThingies\r\n```\r\n\r\n\u003c/details\u003e\r\n\r\nOne idea to fix this would be to infer all of a command's default values the first time an instance is created as a module. Because an instance of the command *is* instantiated immediately: the one that is actually going to get run. The later ones are just throwaways. But if upon first instantiation, we inspected the instance's field values immediately and cached them into the `CommandInfo` itself, then we'd be able to reuse those values from the cache whenever `getDefaultValue()` is subsequently called, without instantiating throwaway instances.","author":{"url":"https://github.com/ctrueden","@type":"Person","name":"ctrueden"},"datePublished":"2024-03-19T14:45:34.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":0},"url":"https://github.com/476/scijava-common/issues/476"}

route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:26666446-0cc3-f436-4e8f-641b12231774
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idCB00:3346BC:68DF5:8F460:6969C597
html-safe-noncedcb5c00c1caa5763d1d581476e1b1eedb284e3bdc3c4a4d7ff38bddc8ba9bf56
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDQjAwOjMzNDZCQzo2OERGNTo4RjQ2MDo2OTY5QzU5NyIsInZpc2l0b3JfaWQiOiI1MDQ0ODkwMTk1NjMwNjA1NzE5IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0=
visitor-hmacf957288232f9147e3a06df1a192f1c68ccb1cbc68ae80c29b49ffa8b883fcbf1
hovercard-subject-tagissue:2195176463
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/scijava/scijava-common/476/issue_layout
twitter:imagehttps://opengraph.githubassets.com/cd447af0f3384c5f4981fbdfc75041376bbdc0d4d1890418df135cbe8f22ef03/scijava/scijava-common/issues/476
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/cd447af0f3384c5f4981fbdfc75041376bbdc0d4d1890418df135cbe8f22ef03/scijava/scijava-common/issues/476
og:image:altAs discussed in this Zulip thread, when invoking a SciJava Command plugin, multiple instances of the command might get instantiated and then thrown away, just to retrieve default parameter values. ...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamectrueden
hostnamegithub.com
expected-hostnamegithub.com
Noneacedec8b5f975d9e3d494ddd8f949b0b8a0de59d393901e26f73df9dcba80056
turbo-cache-controlno-preview
go-importgithub.com/scijava/scijava-common git https://github.com/scijava/scijava-common.git
octolytics-dimension-user_id1262770
octolytics-dimension-user_loginscijava
octolytics-dimension-repository_id3594497
octolytics-dimension-repository_nwoscijava/scijava-common
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id3594497
octolytics-dimension-repository_network_root_nwoscijava/scijava-common
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release83c08c21cdda978090dc44364b71aa5bc6dcea79
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/scijava/scijava-common/issues/476#start-of-content
https://github.com/
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fscijava%2Fscijava-common%2Fissues%2F476
GitHub CopilotWrite better code with AIhttps://github.com/features/copilot
GitHub SparkBuild and deploy intelligent appshttps://github.com/features/spark
GitHub ModelsManage and compare promptshttps://github.com/features/models
MCP RegistryNewIntegrate external toolshttps://github.com/mcp
ActionsAutomate any workflowhttps://github.com/features/actions
CodespacesInstant dev environmentshttps://github.com/features/codespaces
IssuesPlan and track workhttps://github.com/features/issues
Code ReviewManage code changeshttps://github.com/features/code-review
GitHub Advanced SecurityFind and fix vulnerabilitieshttps://github.com/security/advanced-security
Code securitySecure your code as you buildhttps://github.com/security/advanced-security/code-security
Secret protectionStop leaks before they starthttps://github.com/security/advanced-security/secret-protection
Why GitHubhttps://github.com/why-github
Documentationhttps://docs.github.com
Bloghttps://github.blog
Changeloghttps://github.blog/changelog
Marketplacehttps://github.com/marketplace
View all featureshttps://github.com/features
Enterpriseshttps://github.com/enterprise
Small and medium teamshttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
App Modernizationhttps://github.com/solutions/use-case/app-modernization
DevSecOpshttps://github.com/solutions/use-case/devsecops
DevOpshttps://github.com/solutions/use-case/devops
CI/CDhttps://github.com/solutions/use-case/ci-cd
View all use caseshttps://github.com/solutions/use-case
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
View all industrieshttps://github.com/solutions/industry
View all solutionshttps://github.com/solutions
AIhttps://github.com/resources/articles?topic=ai
Software Developmenthttps://github.com/resources/articles?topic=software-development
DevOpshttps://github.com/resources/articles?topic=devops
Securityhttps://github.com/resources/articles?topic=security
View all topicshttps://github.com/resources/articles
Customer storieshttps://github.com/customer-stories
Events & webinarshttps://github.com/resources/events
Ebooks & reportshttps://github.com/resources/whitepapers
Business insightshttps://github.com/solutions/executive-insights
GitHub Skillshttps://skills.github.com
Documentationhttps://docs.github.com
Customer supporthttps://support.github.com
Community forumhttps://github.com/orgs/community/discussions
Trust centerhttps://github.com/trust-center
Partnershttps://github.com/partners
GitHub SponsorsFund open source developershttps://github.com/sponsors
Security Labhttps://securitylab.github.com
Maintainer Communityhttps://maintainers.github.com
Acceleratorhttps://github.com/accelerator
Archive Programhttps://archiveprogram.github.com
Topicshttps://github.com/topics
Trendinghttps://github.com/trending
Collectionshttps://github.com/collections
Enterprise platformAI-powered developer platformhttps://github.com/enterprise
GitHub Advanced SecurityEnterprise-grade security featureshttps://github.com/security/advanced-security
Copilot for BusinessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/premium-support
Pricinghttps://github.com/pricing
Search syntax tipshttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
documentationhttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fscijava%2Fscijava-common%2Fissues%2F476
Sign up https://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=scijava%2Fscijava-common
Reloadhttps://github.com/scijava/scijava-common/issues/476
Reloadhttps://github.com/scijava/scijava-common/issues/476
Reloadhttps://github.com/scijava/scijava-common/issues/476
scijava https://github.com/scijava
scijava-commonhttps://github.com/scijava/scijava-common
Notifications https://github.com/login?return_to=%2Fscijava%2Fscijava-common
Fork 53 https://github.com/login?return_to=%2Fscijava%2Fscijava-common
Star 90 https://github.com/login?return_to=%2Fscijava%2Fscijava-common
Code https://github.com/scijava/scijava-common
Issues 169 https://github.com/scijava/scijava-common/issues
Pull requests 16 https://github.com/scijava/scijava-common/pulls
Actions https://github.com/scijava/scijava-common/actions
Projects 0 https://github.com/scijava/scijava-common/projects
Wiki https://github.com/scijava/scijava-common/wiki
Security Uh oh! There was an error while loading. Please reload this page. https://github.com/scijava/scijava-common/security
Please reload this pagehttps://github.com/scijava/scijava-common/issues/476
Insights https://github.com/scijava/scijava-common/pulse
Code https://github.com/scijava/scijava-common
Issues https://github.com/scijava/scijava-common/issues
Pull requests https://github.com/scijava/scijava-common/pulls
Actions https://github.com/scijava/scijava-common/actions
Projects https://github.com/scijava/scijava-common/projects
Wiki https://github.com/scijava/scijava-common/wiki
Security https://github.com/scijava/scijava-common/security
Insights https://github.com/scijava/scijava-common/pulse
New issuehttps://github.com/login?return_to=https://github.com/scijava/scijava-common/issues/476
New issuehttps://github.com/login?return_to=https://github.com/scijava/scijava-common/issues/476
Commands get instantiated multiple times per runhttps://github.com/scijava/scijava-common/issues/476#top
bughttps://github.com/scijava/scijava-common/issues?q=state%3Aopen%20label%3A%22bug%22
https://github.com/ctrueden
https://github.com/ctrueden
ctruedenhttps://github.com/ctrueden
on Mar 19, 2024https://github.com/scijava/scijava-common/issues/476#issue-2195176463
this Zulip threadhttps://imagesc.zulipchat.com/#narrow/stream/327495-scenery.2Bsciview/topic/Class.20initialization.20in.20Add.20commands
retrieve default parameter valueshttps://github.com/scijava/scijava-common/blob/scijava-common-2.98.0/src/main/java/org/scijava/command/CommandModuleItem.java#L168
bughttps://github.com/scijava/scijava-common/issues?q=state%3Aopen%20label%3A%22bug%22
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.