apache / apache/netbeans

New NB Platform application throws java.lang.reflect.InaccessibleObjectException

Open
#8,903 0 comments 0 reactions 0 assignees View on GitHub
kind:bug Maven needs:triage Platform
Dominant language
Java
Stars
3.1k
Forks
935
Avg merge
2d 3h
Merged PRs (30d)
17

Description

### Apache NetBeans version

Apache NetBeans 27

### What happened

When a new Netbeans Platform Application is created, running it throws `java.lang.reflect.InaccessibleObjectException`.

The maven archetype includes `jpms-flags` for the app module but they don't seem to apply to runtime. Taking out the jpms-flag for java breaks the build, but taking it out or adding it back doesn't seem to have any effect when running the application.

Stacktrace when running the application includes:
```
SEVERE: No way to find original stream handler for jar protocol
java.lang.reflect.InaccessibleObjectException: Unable to make field transient java.net.URLStreamHandler java.net.URL.handler accessible: module java.base does not "opens java.net" to unnamed module @3b07d329
at java.base/java.lang.reflect.AccessibleObject.throwInaccessibleObjectException(AccessibleObject.java:353)
at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:329)
at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:277)
at java.base/java.lang.reflect.Field.checkCanSetAccessible(Field.java:179)
at java.base/java.lang.reflect.Field.setAccessible(Field.java:173)
at org.netbeans.ProxyURLStreamHandlerFactory.register(ProxyURLStreamHandlerFactory.java:59)
at org.netbeans.JarClassLoader.(JarClassLoader.java:143)
at org.netbeans.MainImpl.execute(MainImpl.java:166)
at org.netbeans.MainImpl.main(MainImpl.java:60)
at org.netbeans.Main.main(Main.java:58)
```
The application can run, it just has no access to `java.net`.

### Language / Project Type / NetBeans Component

Netbeans Platform

### How to reproduce

Create a new Netbeans application, build and run it.

Note: you may need to take out the security-manager flag as per https://github.com/apache/netbeans-mavenutils-archetype-netbeans-platform-app-archetype/pull/19

### Did this work correctly in an earlier version?

No / Don't know

### Operating System

Both Windows 10 and Ubuntu 24

### JDK

Oracle jdk-24

### Apache NetBeans packaging

Apache NetBeans platform

### Anything else

I created a PR that solves the issue, but I suspect there are better ways. See https://github.com/apache/netbeans-mavenutils-archetype-netbeans-platform-app-archetype/pull/20

I couldn't find information on who processes the jpms-flags used in the pom. That may be a better place to actually use the same flags on runtime. Is the `nbm-maven-plugin`?

### Are you willing to submit a pull request?

Yes

Contributor guide

Open the contributing guide

Research direction

Reproduce the failure with the NetBeans Platform application archetype on JDK 24, starting with its jpms-flags and the stack-trace entry points ProxyURLStreamHandlerFactory.register and JarClassLoader. Inspect the nbm-maven-plugin and PR #20 to understand how runtime flags are handled. Done means a generated application runs without the InaccessibleObjectException and retains java.net access.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
build-system
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.