#2536 NPE when compiling scripts

SlimerDude Sun 15 May 2016

I was trying to compile a script into a Fantom pod file. I wanted an actual .pod file and not a Pod instance, so I could read the generated .apidoc files.

But I kept getting an NPE at the last stage when the pod file was being written out. This little patch fixes it:

diff -r 8b38678076b7 src/compiler/fan/steps/WritePod.fan
--- a/src/compiler/fan/steps/WritePod.fan	Tue Apr 19 17:11:16 2016 -0400
+++ b/src/compiler/fan/steps/WritePod.fan	Sun May 15 19:36:36 2016 +0100
@@ -71,7 +71,8 @@
         writeStr(zip, `locale/en.props`, compiler.localeProps)
       // write resource files
-      compiler.resFiles.each |file| { writeRes(zip, file) }
+      if (compiler.resFiles != null)
+        compiler.resFiles.each |file| { writeRes(zip, file) }
       // if including fandoc write it out too
       if (compiler.input.includeDoc) writeDocs(zip)

compiler.resFiles is null because of InitInput.initFiles():

private Void initFiles()
  if (input.mode !== CompilerInputMode.file) return

  // map pod facets to src/res files
  compiler.srcFiles = findFiles(input.srcFiles, "fan")
  compiler.resFiles = findFiles(input.resFiles, null)
  compiler.jsFiles  = findFiles(input.jsFiles,  "js")

Because I'm compiling a script, input.mode is CompilerInputMode.str, so compiler.resFiles is never set to a value

With the null check patch, it all works great! I can now generate a valid Fantom .pod file from just a script.

matthew Mon 16 May 2016

Ticket promoted to #2536 and assigned to matthew

matthew Mon 16 May 2016

Ticket resolved in 1.0.69

Applied the fix to check if resFiles is null before iterating them.

Login or Signup to reply.