René's URL Explorer Experiment


Title: Returning contextClassLoader in Platfom.getClassLoader() can mess up in an OSGI application · Issue #574 · nativelibs4java/nativelibs4java · GitHub

Open Graph Title: Returning contextClassLoader in Platfom.getClassLoader() can mess up in an OSGI application · Issue #574 · nativelibs4java/nativelibs4java

X Title: Returning contextClassLoader in Platfom.getClassLoader() can mess up in an OSGI application · Issue #574 · nativelibs4java/nativelibs4java

Description: TL;DR: It should be possible to force Platfom.getClassLoader(Class) to prefer the classloader of the class over the context classloader of the thread. Details: I am running JavaCL in an OSGi bundle (a plugin for a GUI application call...

Open Graph Description: TL;DR: It should be possible to force Platfom.getClassLoader(Class) to prefer the classloader of the class over the context classloader of the thread. Details: I am running JavaCL in an OSGi bun...

X Description: TL;DR: It should be possible to force Platfom.getClassLoader(Class<?>) to prefer the classloader of the class over the context classloader of the thread. Details: I am running JavaCL in an OS...

Opengraph URL: https://github.com/nativelibs4java/nativelibs4java/issues/574

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Returning contextClassLoader in Platfom.getClassLoader() can mess up in an OSGI application","articleBody":"**TL;DR:** It should be possible to force Platfom.getClassLoader(Class\u003c?\u003e) to prefer the classloader of the class over the context classloader of the thread.\n\n---\n\n**Details:** I am running JavaCL in an OSGi bundle (a plugin for a GUI application called Cytoscape). The plugin provides methods that are executed on threads created by the application framework. I try to call kernels from the application-created thread, which results in some class loading for event callbacks with CallbackNativeImplementer. But that throws NoClassDefFoundError (stacktrace below). \n\nAfter some funny debugging, I realized that the problem is that the parent classloader of CallbackNativeImplementer is NOT the bundle classloader - it is the classloader returned by Platfom.getClassLoader() (set in the constructor of CallbackNativeImplementer). And Platfom.getClassLoader() first checks Thread.currentThread().getContextClassLoader() which returns the class loader of the application framework, which does not see the bundle resources.\n\nAs a workaround, I use Thread.currentThread().setContextClassLoader() to set the correct class loader before invoking any JavaCL methods, but that seems hacky. I am not sure for what use cases the context classloader is more appropriate than the classloader of the active class, but maybe there could be some setting to give preference to the class's classloader over the thread... \n\nOr is there some other way to enforce proper classloader in this case?\n\nI'll be happy to work on this issue once someone from the team confirms what is the correct way to address it.\n\nNote that I am not using the OSGi version of JavaCL, instead, I embed the JavaCL jars within my bundle (with \u003cEmbed-Dependency\u003e directive of Maven bundle plugin) as this is mandated by the Cytoscape plugin development rules. \nI however think that the problem would arise the same if JavaCL was used as an OSGi bundle (the calling thread would still provide different class loader). \nI did some tests with having JavaCL as a separete bundle and the problem did not go away, although I am not certain I did everything well.\n\nThe promised stacktrace:\n\n```\nCaused by: java.lang.NoClassDefFoundError: com/nativelibs4java/opencl/library/IOpenCLLibrary$clSetEventCallback_arg1_callback\n        at java.lang.ClassLoader.defineClass1(Native Method)\n        at java.lang.ClassLoader.defineClass(ClassLoader.java:763)\n        at java.lang.ClassLoader.defineClass(ClassLoader.java:642)\n        at org.bridj.CallbackNativeImplementer.defineClass(CallbackNativeImplementer.java:214)\n        at org.bridj.CallbackNativeImplementer.getCallbackImplType(CallbackNativeImplementer.java:103)\n        at org.bridj.CRuntime.register(CRuntime.java:426)\n        at org.bridj.CRuntime.registerFamily(CRuntime.java:483)\n        at org.bridj.CRuntime.register(CRuntime.java:470)\n        at org.bridj.CRuntime.register(CRuntime.java:345)\n        at org.bridj.CRuntime$CTypeInfo.\u003cinit\u003e(CRuntime.java:126)\n        at org.bridj.CRuntime.getTypeInfo(CRuntime.java:336)\n        at org.bridj.BridJ.getTypeInfo(BridJ.java:377)\n        at org.bridj.BridJ.initialize(BridJ.java:1126)\n        at org.bridj.NativeObject.\u003cinit\u003e(NativeObject.java:50)\n        at org.bridj.Callback.\u003cinit\u003e(Callback.java:60)\n        at com.nativelibs4java.opencl.library.IOpenCLLibrary$clSetEventCallback_arg1_callback.\u003cinit\u003e(IOpenCLLibrary.java:576)\n        at com.nativelibs4java.opencl.CLEvent$3.\u003cinit\u003e(CLEvent.java:128)\n        at com.nativelibs4java.opencl.CLEvent.\u003cclinit\u003e(CLEvent.java:128)\n        at com.nativelibs4java.opencl.CLKernel.enqueueNDRange(CLKernel.java:482)\n        at cz.cas.mbu.gn.compute.GNCompute.executeKernel(GNCompute.java:121)\n        at cz.cas.mbu.gn.compute.GNCompute.computeAdditiveRegulation(GNCompute.java:342)\n        at cz.cas.mbu.cygngpu.internal.PredictSingleRegulationsTask.run(PredictSingleRegulationsTask.java:176)\n        at org.cytoscape.work.internal.task.JDialogTaskManager$TaskRunnable.innerRun(JDialogTaskManager.java:326)\n        at org.cytoscape.work.internal.task.JDialogTaskManager$TaskRunnable.run(JDialogTaskManager.java:355)\n        ... 5 more\nCaused by: java.lang.ClassNotFoundException: com.nativelibs4java.opencl.library.IOpenCLLibrary$clSetEventCallback_arg1_callback\n        at java.lang.ClassLoader.findClass(ClassLoader.java:530)\n        at java.lang.ClassLoader.loadClass(ClassLoader.java:424)\n        at java.lang.ClassLoader.loadClass(ClassLoader.java:357)\n        ... 29 more\n```\n","author":{"url":"https://github.com/martinmodrak","@type":"Person","name":"martinmodrak"},"datePublished":"2016-06-28T10:57:31.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":0},"url":"https://github.com/574/nativelibs4java/issues/574"}

route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:d4c44378-22c8-a78b-5feb-736fa70fa4d3
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-id9B34:3D4A65:75650A:9FFAC4:697BD8B2
html-safe-nonce33d90a5e31d9cf3c8ff13eee197f72bce2a8ceed9130cbf8a5c0fdfb7d717987
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5QjM0OjNENEE2NTo3NTY1MEE6OUZGQUM0OjY5N0JEOEIyIiwidmlzaXRvcl9pZCI6Ijc2NDIzMTM5NjQ3MjU3MjEyNjYiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ==
visitor-hmac67f150a50bd0991ddcb6d2ed7251fd61de35664350127c9cfc2ba695930f1883
hovercard-subject-tagissue:162658151
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/nativelibs4java/nativelibs4java/574/issue_layout
twitter:imagehttps://opengraph.githubassets.com/11492bc74c712415750acfb9f030a307eecf229ca886e0cd63b2570ee27f23f7/nativelibs4java/nativelibs4java/issues/574
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/11492bc74c712415750acfb9f030a307eecf229ca886e0cd63b2570ee27f23f7/nativelibs4java/nativelibs4java/issues/574
og:image:altTL;DR: It should be possible to force Platfom.getClassLoader(Class) to prefer the classloader of the class over the context classloader of the thread. Details: I am running JavaCL in an OSGi bun...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamemartinmodrak
hostnamegithub.com
expected-hostnamegithub.com
Noned9273cb6ee4e18acd2ce5be1d6a9f9b3984f728c67ac95709fc3d38fedbb2967
turbo-cache-controlno-preview
go-importgithub.com/nativelibs4java/nativelibs4java git https://github.com/nativelibs4java/nativelibs4java.git
octolytics-dimension-user_id11545921
octolytics-dimension-user_loginnativelibs4java
octolytics-dimension-repository_id2194042
octolytics-dimension-repository_nwonativelibs4java/nativelibs4java
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id2194042
octolytics-dimension-repository_network_root_nwonativelibs4java/nativelibs4java
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
release784b44795f41068c6521c17f38ad6ed44ce1775c
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/nativelibs4java/nativelibs4java/issues/574#start-of-content
https://github.com/
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fnativelibs4java%2Fnativelibs4java%2Fissues%2F574
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%2Fnativelibs4java%2Fnativelibs4java%2Fissues%2F574
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=nativelibs4java%2Fnativelibs4java
Reloadhttps://github.com/nativelibs4java/nativelibs4java/issues/574
Reloadhttps://github.com/nativelibs4java/nativelibs4java/issues/574
Reloadhttps://github.com/nativelibs4java/nativelibs4java/issues/574
nativelibs4java https://github.com/nativelibs4java
nativelibs4javahttps://github.com/nativelibs4java/nativelibs4java
Notifications https://github.com/login?return_to=%2Fnativelibs4java%2Fnativelibs4java
Fork 83 https://github.com/login?return_to=%2Fnativelibs4java%2Fnativelibs4java
Star 294 https://github.com/login?return_to=%2Fnativelibs4java%2Fnativelibs4java
Code https://github.com/nativelibs4java/nativelibs4java
Issues 19 https://github.com/nativelibs4java/nativelibs4java/issues
Pull requests 3 https://github.com/nativelibs4java/nativelibs4java/pulls
Actions https://github.com/nativelibs4java/nativelibs4java/actions
Projects 0 https://github.com/nativelibs4java/nativelibs4java/projects
Wiki https://github.com/nativelibs4java/nativelibs4java/wiki
Security 0 https://github.com/nativelibs4java/nativelibs4java/security
Insights https://github.com/nativelibs4java/nativelibs4java/pulse
Code https://github.com/nativelibs4java/nativelibs4java
Issues https://github.com/nativelibs4java/nativelibs4java/issues
Pull requests https://github.com/nativelibs4java/nativelibs4java/pulls
Actions https://github.com/nativelibs4java/nativelibs4java/actions
Projects https://github.com/nativelibs4java/nativelibs4java/projects
Wiki https://github.com/nativelibs4java/nativelibs4java/wiki
Security https://github.com/nativelibs4java/nativelibs4java/security
Insights https://github.com/nativelibs4java/nativelibs4java/pulse
New issuehttps://github.com/login?return_to=https://github.com/nativelibs4java/nativelibs4java/issues/574
New issuehttps://github.com/login?return_to=https://github.com/nativelibs4java/nativelibs4java/issues/574
Returning contextClassLoader in Platfom.getClassLoader() can mess up in an OSGI applicationhttps://github.com/nativelibs4java/nativelibs4java/issues/574#top
https://github.com/martinmodrak
https://github.com/martinmodrak
martinmodrakhttps://github.com/martinmodrak
on Jun 28, 2016https://github.com/nativelibs4java/nativelibs4java/issues/574#issue-162658151
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.