#1079 ResolveImports: catch CompilerErr around resolveImportedTypes() call

alex_panchenko Tue 20 Apr 2010

diff -r ecb44c5ba4f6 src/compiler/fan/steps/ResolveImports.fan
--- a/src/compiler/fan/steps/ResolveImports.fan	Mon Apr 19 19:35:42 2010 -0400
+++ b/src/compiler/fan/steps/ResolveImports.fan	Tue Apr 20 11:15:13 2010 +0700
@@ -52,7 +52,14 @@
     // process each unit for CompilationUnit.importedTypes
     units.each |CompilationUnit unit|
     {
-      resolveImportedTypes(unit)
+      try {
+        resolveImportedTypes(unit)
+      }
+      catch (CompilerErr e)
+      {
+        errReport(e)
+        return
+      }
     }
     bombIfErr

As I've experienced the following error which was not reported:

compiler::CompilerErr: Java package 'xxx' not found
  compilerJava::JavaBridge.resolvePod (JavaBridge.fan:46)
  compiler::CNamespace.resolvePod (CNamespace.fan:198)
  compiler::TypeParser.resolve (TypeParser.fan:44)
  compiler::CNamespace.resolveType (CNamespace.fan:232)
  compiler::TypeParser.loadAny (TypeParser.fan:105)
  compiler::TypeParser.loadFunc (TypeParser.fan:158)
  compiler::TypeParser.loadAny (TypeParser.fan:82)
  compiler::TypeParser.loadTop (TypeParser.fan:71)
  compiler::TypeParser.resolve (TypeParser.fan:48)
  compiler::CNamespace.resolveType (CNamespace.fan:232)
  compiler::ReflectNamespace.importType (ReflectNamespace.fan:64)
  compiler::ReflectType.make$ (ReflectType.fan:28)
  compiler::ReflectType.make (ReflectType.fan)
  compiler::ReflectPod.resolveType (ReflectPod.fan:52)
  compiler::ReflectPod.types (ReflectPod.fan:34)
  fan.sys.List.each (List.java:527)
  compiler::ReflectPod.types (ReflectPod.fan:34)
  compiler::ResolveImports.resolveImportedTypes (ResolveImports.fan:161)
  fan.sys.List.each (List.java:527)
  compiler::ResolveImports.resolveImportedTypes (ResolveImports.fan:158)
  31 More...

This java package was not used directly in the pod being compiled, it was used in one of the dependencies, but it was not available on classpath when the current pod was compiled.

brian Wed 21 Apr 2010

can you post a snippet of the test code that caused that exception so we can get it into the test suite?

alex_panchenko Wed 21 Apr 2010

The issue can be reproduced by performing the following steps:

  • compile this class to JAR
package com.xored.topic1079;

public class JA {
	public int execute() {
		return 1;
	}
}
  • remove this check -o ! -d "$FAN_CP" in fanlaunch as it doesn't allow complex classpaths
  • export FAN_CP=your-fan-home/lib/java/sys.jar:path-to-my.jar
  • compile this class as Topic1079A pod
using [java] com.xored.topic1079

class Topic1079 : JA {
  Void main(Str[] args) {
    echo(execute())
  }
}
  • unset FAN_CP
  • compile this class as Topic1079B pod
using Topic1079A

class Topic1079B {
  Void main(Str[] args) {
    Topic1079().main(args);
    echo("OK")
  }
}

Without the patch the output is:

compile [Topic1079B]
  Compile [Topic1079B]
    FindSourceFiles [1 files]
BUILD FAILED [760ms]!

After patch the output is better:

compile [Topic1079B]
  Compile [Topic1079B]
    FindSourceFiles [1 files]
null: Java package 'com.xored.topic1079' not found
BUILD FAILED [561ms]!

brian Thu 22 Apr 2010

Promoted to ticket #1079 and assigned to brian

Patch seems simple and safe, but I'd like to read thru that code and just verify.

Things are a bit crazy until first week of May, but then I should have time to go thru ticket list and do another official build.

brian Thu 6 May 2010

Ticket resolved in 1.0.53

Take a look at this changeset

I wrapped both resolveImports and resolveImportedTypes just in case to report an error.

Login or Signup to reply.