[Bug]: Module Resource Files Not Found When Using FileSystemHelper.readJson
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 44
- Forks
- 19
- Avg merge
- 1d 12h
- Merged PRs (30d)
- 4
Description
Is there an existing issue for this?
- I have searched the existing issues
Current Behavior
When using the io.neonbee.internal.helper.FileSystemHelper.readJson method to load resource files within a NeonBee module, the resource file cannot be found. This occurs because the FileSystemHelper.readJson method relies on Vert.x's internal file resolver, which uses the application ClassLoader. The application ClassLoader is only aware of resource files within the NeonBee core, not those in the module's resources.
Expected Behavior
The FileSystemHelper.readJson method should be able to locate and load resource files from within the module’s resources when called from a NeonBee module.
Steps To Reproduce
- Create a NeonBee module with its own resources, such as a JSON file (somefile.json).
- Use the FileSystemHelper.readJson method in the module to attempt to load the JSON file from the module's resources.
- Observe that the file cannot be found, and an error is thrown.
Environment
- NeonBee: 0.37.0
Relevant log output
No response
Anything else?
A workaround involves manually loading the resource file using the module's ClassLoader, as shown in the following code snippet:
Future.future(promise -> {
InputStream resourceAsStream = this.getClass().getClassLoader()
.getResourceAsStream("somefile.json");
try (BufferedReader reader = new BufferedReader(new InputStreamReader(resourceAsStream, StandardCharsets.UTF_8))) {
StringBuilder stringBuilder = new StringBuilder();
String line;
while ((line = reader.readLine()) != null) {
stringBuilder.append(line);
}
promise.complete(new JsonObject(stringBuilder.toString()));
} catch (IOException e) {
throw new RuntimeException(e);
}
})
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at io.neonbee.internal.helper.FileSystemHelper.readJson and inspect how its Vert.x file resolution handles resources loaded from a module ClassLoader. Reproduce the issue with a module containing somefile.json, then verify that readJson can load that module resource without the manual ClassLoader workaround.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100