Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-8044

MissingPropertyException for java style local variables



    • Bug
    • Status: Open
    • Major
    • Resolution: Unresolved
    • 2.4.7
    • None
    • groovy-runtime
    • KUbuntu16.10 but also present on Windows 7, Mac OS 10.9.5


      Hey Guys,
      First off: Sorry if this is a fault on my side but I highly doubt it.

      I am using Groovy to compile java and groovy files on the fly to use them as regular Class instances.
      I use my implementation of GroovyResourceLoader but I can confirm that it works, since if I break it purposely, Groovy complains about unknown class definitions during compile-time (of the script).

      So what happens is that I can successfully instantiate the freshly loaded class but as soon as I call a method which has a java style definition, it crashes during runtime.

      So a few examples:

          public URL loadGroovySource(String fileName) throws MalformedURLException {
              if (fileName.startsWith("de.my.packages")) {
                  String className = fileName.substring("de.my.packages".length()).replace('.', '/');
                  for (String extension : new String[] { ".java", ".groovy" }) {
                      File classFile = new File(basicPath, className + extension);
                      if (classFile.exists()) {
                          System.out.println("FOUND " + classFile.getAbsolutePath());
                          return classFile.toURI().toURL();
              return null;

      Please ignore the fact that the variable names are misleading. Actually fileName should be className and className should be fileName...

      Now the code to get those Classes:

      groovyClassLoader = new GroovyClassLoader(Thread.currentThread().getContextClassLoader());
      groovyClassLoader.setResourceLoader(new CustomGroovyResourceLoader(current));
      File f = new File(filePath);
      if (!f.exists()) {
        throw new FileNotFoundException(filePath);
      return groovyClassLoader.parseClass(f);

      The error now is:

      No such property: de for class: de.my.package.script2
      Possible solutions: name
      groovy.lang.MissingPropertyException: No such property: de for class: de.my.package.script2
      Possible solutions: name
              at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:53)
              at org.codehaus.groovy.runtime.callsite.GetEffectivePogoPropertySite.getProperty(GetEffectivePogoPropertySite.java:87)
              at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callGroovyObjectGetProperty(AbstractCallSite.java:307)
              at de.my.package.script2.getInterfaceVersion(script2.java:27)
              at java.lang.Thread.run(Thread.java:745)
      No such property: de for class: de.my.package.script2
      Possible solutions: name

      Now my actual script file looks like this at that line:

      de.my.package.lib.myJavaFile theJavaFile = new de.my.package.lib.myJavaFile();

      This means that for some reason during runtime it quits after the . of de.
      Initially the code looked like this though:

      myJavaFile theJavaFile = new myJavaFile();

      This lead to the same Exception, I tried specifying the correct package manually to rule out some errors with the resolution (Groovy definately knows the myJavaFile class because parseClass would fail).

      Please note that my package isn't really "de.my.package", since package is a reserved keyword but I had to edit it out.

      What does work is "def theJavaFile = new myJavaFile();".
      What ALSO works is the java style definition for files available through the classpath (e.g. conventional code, anything from java.lang, ...)

      Am I probably missing some compilersettings to allow java compability?
      Thanks in Advance




            Unassigned Unassigned
            MeFisto94 MeFisto94
            0 Vote for this issue
            2 Start watching this issue