Skip to content

Fix views-react feature failing in native CLI due to classpath directory lookup - #3080

Open
lissam1 wants to merge 1 commit into
4.10.xfrom
fix-2709
Open

Fix views-react feature failing in native CLI due to classpath directory lookup#3080
lissam1 wants to merge 1 commit into
4.10.xfrom
fix-2709

Conversation

@lissam1

@lissam1 lissam1 commented Apr 14, 2026

Copy link
Copy Markdown
Member

Summary

Fixes a NullPointerException when using the views-react feature with the native mn CLI. The issue was caused by relying on classpath directory lookup, which does not work reliably in GraalVM native images.

Problem

Running:

mn create-app --features=views-react demo1

resulted in:

| Error null
java.lang.NullPointerException
    at io.micronaut.starter.feature.view.React.apply(...)

This occurred in:

  • installed mn CLI
  • native image build

Root Cause

The implementation used:

getResource("views/react")

to resolve a directory and then built child URLs from it.

While this works on the JVM, in GraalVM native image:

  • individual resources are included
  • but directory resources are not accessible via getResource

As a result:

getResource("views/react") == null

leading to the NPE.


Solution

Replace directory-based lookup with per-file resource resolution:

var resourceUrl = Objects.requireNonNull(
    classLoader.getResource("views/react/" + fileName),
    () -> "Missing bundled resource " + resourceName
);

This ensures:

  • compatibility with native image
  • explicit failure if a resource is missing
  • no reliance on directory classpath behavior

Changes

  • Removed directory-based resource resolution
  • Switched to per-file lookup for all frontend templates
  • Added clear error messages using Objects.requireNonNull
  • Removed unused URL / MalformedURLException logic

Validation

Tested successfully with:

./gradlew clean :starter-core:build 
./gradlew micronaut-cli:nativeCompile --no-daemon
./starter-cli/build/native/nativeCompile/mn create-app --stacktrace --features=views-react demo1nativecheck

Closes: #2709

@lissam1
lissam1 changed the base branch from 5.0.x to 4.10.x April 21, 2026 09:15
@lissam1 lissam1 added the type: bug Something isn't working label Apr 21, 2026
@lissam1 lissam1 moved this to Ready for Review in 4.10.13 Release Apr 21, 2026
@lissam1 lissam1 moved this to Ready for Review in 4.10.14 Release May 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

relates-to: graal type: bug Something isn't working

Projects

Status: Ready for Review

Development

Successfully merging this pull request may close these issues.

create-app CLI failed on features=views-react

2 participants