Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NPE in codegen OutputFileMixin #689

Closed
remkop opened this issue May 10, 2019 · 0 comments
Closed

NPE in codegen OutputFileMixin #689

remkop opened this issue May 10, 2019 · 0 comments

Comments

@remkop
Copy link
Owner

remkop commented May 10, 2019

C:\picocli-master>C:\pkg\graalvm-ce-19.0.0\bin\java -cp build\libs\picocli-4.0.0-alpha-3-SNAPSHOT.jar;picocli-codegen\build\libs\picocli-codegen-4.0.0-alpha-3-SNAPSHOT.jar picocli.codegen.aot.graalvm.ReflectionConfigGenerator picocli.AutoComplete$App --output reflect-config.json

java.lang.NullPointerException
        at picocli.codegen.aot.graalvm.OutputFileMixin.writeToFile(OutputFileMixin.java:28)
        at picocli.codegen.aot.graalvm.OutputFileMixin.write(OutputFileMixin.java:20)
        at picocli.codegen.aot.graalvm.ReflectionConfigGenerator$App.call(ReflectionConfigGenerator.java:80)
        at picocli.codegen.aot.graalvm.ReflectionConfigGenerator$App.call(ReflectionConfigGenerator.java:59)
        at picocli.CommandLine.executeUserObject(CommandLine.java:1662)
        at picocli.CommandLine.access$900(CommandLine.java:143)
        at picocli.CommandLine$RunLast.handle(CommandLine.java:2020)
        at picocli.CommandLine$RunLast.handle(CommandLine.java:1987)
        at picocli.CommandLine$AbstractParseResultHandler.execute(CommandLine.java:1854)
        at picocli.CommandLine.execute(CommandLine.java:1783)
        at picocli.codegen.aot.graalvm.ReflectionConfigGenerator.main(ReflectionConfigGenerator.java:90)

Workaround:

--output ./reflect-config.json

Fix:

Index: picocli-codegen/src/main/java/picocli/codegen/aot/graalvm/OutputFileMixin.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- picocli-codegen/src/main/java/picocli/codegen/aot/graalvm/OutputFileMixin.java	(date 1557467944357)
+++ picocli-codegen/src/main/java/picocli/codegen/aot/graalvm/OutputFileMixin.java	(date 1557467944357)
@@ -25,7 +25,8 @@
     private void writeToFile(String result) throws IOException {
         FileWriter writer = null;
         try {
-            if (!outputFile.getParentFile().mkdirs()) {
+            File parent = outputFile.getAbsoluteFile().getParentFile();
+            if (parent != null && !parent.exists() && !parent.mkdirs()) {
                 System.err.println("Unable to mkdirs for " + outputFile.getAbsolutePath());
             }
             writer = new FileWriter(outputFile);
@remkop remkop added this to the 4.0-alpha-3 milestone May 10, 2019
remkop added a commit that referenced this issue May 10, 2019
@remkop remkop closed this as completed May 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant