groovy
  1. groovy
  2. GROOVY-585

groovy can't handle public static nested classes

    Details

    • Type: Bug Bug
    • Status: Closed Closed
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 1.0-beta-7
    • Component/s: None
    • Labels:
      None
    • Number of attachments :
      2

      Description

      stumbled across this bug while doing some drools SMF testing with the groovy semantic module.

      When you try to assign a static nested class to a groovy variable, a groovy.lang.MissingClassException is thrown:

      I wrote a sample class that demonstrates the problem and will attach to this issue.

      The error from the sample class is:

      groovy.lang.MissingClassException: No such class: Foo.Bar in constructor call for class: groovy. At [1:137] groovy.script

      1. Foo.java
        0.5 kB
        Doug Bryant
      2. GroovyNestedClassTest.java
        2 kB
        Doug Bryant

        Activity

        Hide
        Doug Bryant added a comment -

        Sample class with nested static class

        Show
        Doug Bryant added a comment - Sample class with nested static class
        Hide
        Doug Bryant added a comment -

        Test class that uses Foo and generates the error

        error was generated using groovy 1.0 b6

        Show
        Doug Bryant added a comment - Test class that uses Foo and generates the error error was generated using groovy 1.0 b6
        Hide
        Guillaume Laforge added a comment -

        As a temporary workaround, it seems you can do new Foo$Bar() instead of new Foo.Bar(). It seems we have a problem in the way we resolve class names currently :-/

        Show
        Guillaume Laforge added a comment - As a temporary workaround, it seems you can do new Foo$Bar() instead of new Foo.Bar(). It seems we have a problem in the way we resolve class names currently :-/
        Hide
        Mark Proctor added a comment -

        I just tried this and it fails:
        import org.drools.smf.SMFTestFrameWork;
        SMFTestFrameWork.Cheese brie = new SMFTestFrameWork.Cheese("brie");

        However if I do:
        import org.drools.smf.SMFTestFrameWork.Cheese;
        I can use it as:
        Cheese brie = new Cheese("brie");

        Trying to standadise some tests in drools, so would be nice if it could work the conventional way too.

        The error:
        groovy.lang.MissingClassException: No such class: SMFTestFrameWork in cast for c
        lass: groovy. At [-1:-1] groovy.script
        at org.codehaus.groovy.classgen.AsmClassGenerator2.checkValidType(AsmCla
        ssGenerator2.java:4670)
        at org.codehaus.groovy.classgen.AsmClassGenerator2.checkValidType(AsmCla
        ssGenerator2.java:4659)
        at org.codehaus.groovy.classgen.AsmClassGenerator2.visitCastExpression(A
        smClassGenerator2.java:1806)
        at org.codehaus.groovy.classgen.AsmClassGenerator2.evaluateEqual(AsmClas
        sGenerator2.java:3937)
        at org.codehaus.groovy.classgen.AsmClassGenerator2.visitBinaryExpression
        (AsmClassGenerator2.java:1145)
        at org.codehaus.groovy.ast.expr.BinaryExpression.visit(BinaryExpression.
        java:335)
        at org.codehaus.groovy.classgen.AsmClassGenerator2.visitAndAutoboxBoolea
        n(AsmClassGenerator2.java:4094)
        at org.codehaus.groovy.classgen.AsmClassGenerator2.evaluateExpression(As
        mClassGenerator2.java:1113)
        at org.codehaus.groovy.classgen.AsmClassGenerator2.visitReturnStatement(
        AsmClassGenerator2.java:1040)
        at org.codehaus.groovy.ast.stmt.ReturnStatement.visit(ReturnStatement.ja
        va:69)
        at org.codehaus.groovy.ast.CodeVisitorSupport.visitBlockStatement(CodeVi
        sitorSupport.java:108)
        at org.codehaus.groovy.ast.stmt.BlockStatement.visit(BlockStatement.java
        :79)
        at org.codehaus.groovy.classgen.AsmClassGenerator2.visitMethod(AsmClassG
        enerator2.java:404)
        at org.codehaus.groovy.ast.ClassNode.visitContents(ClassNode.java:811)
        at org.codehaus.groovy.classgen.AsmClassGenerator2.visitClass(AsmClassGe
        nerator2.java:306)
        at org.codehaus.groovy.control.CompilationUnit$5.call(CompilationUnit.ja
        va:579)
        at org.codehaus.groovy.control.CompilationUnit.applyToPrimaryClassNodes(
        CompilationUnit.java:844)
        at org.codehaus.groovy.control.CompilationUnit.classgen(CompilationUnit.
        java:540)
        at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.j
        ava:446)

        Show
        Mark Proctor added a comment - I just tried this and it fails: import org.drools.smf.SMFTestFrameWork; SMFTestFrameWork.Cheese brie = new SMFTestFrameWork.Cheese("brie"); However if I do: import org.drools.smf.SMFTestFrameWork.Cheese; I can use it as: Cheese brie = new Cheese("brie"); Trying to standadise some tests in drools, so would be nice if it could work the conventional way too. The error: groovy.lang.MissingClassException: No such class: SMFTestFrameWork in cast for c lass: groovy. At [-1:-1] groovy.script at org.codehaus.groovy.classgen.AsmClassGenerator2.checkValidType(AsmCla ssGenerator2.java:4670) at org.codehaus.groovy.classgen.AsmClassGenerator2.checkValidType(AsmCla ssGenerator2.java:4659) at org.codehaus.groovy.classgen.AsmClassGenerator2.visitCastExpression(A smClassGenerator2.java:1806) at org.codehaus.groovy.classgen.AsmClassGenerator2.evaluateEqual(AsmClas sGenerator2.java:3937) at org.codehaus.groovy.classgen.AsmClassGenerator2.visitBinaryExpression (AsmClassGenerator2.java:1145) at org.codehaus.groovy.ast.expr.BinaryExpression.visit(BinaryExpression. java:335) at org.codehaus.groovy.classgen.AsmClassGenerator2.visitAndAutoboxBoolea n(AsmClassGenerator2.java:4094) at org.codehaus.groovy.classgen.AsmClassGenerator2.evaluateExpression(As mClassGenerator2.java:1113) at org.codehaus.groovy.classgen.AsmClassGenerator2.visitReturnStatement( AsmClassGenerator2.java:1040) at org.codehaus.groovy.ast.stmt.ReturnStatement.visit(ReturnStatement.ja va:69) at org.codehaus.groovy.ast.CodeVisitorSupport.visitBlockStatement(CodeVi sitorSupport.java:108) at org.codehaus.groovy.ast.stmt.BlockStatement.visit(BlockStatement.java :79) at org.codehaus.groovy.classgen.AsmClassGenerator2.visitMethod(AsmClassG enerator2.java:404) at org.codehaus.groovy.ast.ClassNode.visitContents(ClassNode.java:811) at org.codehaus.groovy.classgen.AsmClassGenerator2.visitClass(AsmClassGe nerator2.java:306) at org.codehaus.groovy.control.CompilationUnit$5.call(CompilationUnit.ja va:579) at org.codehaus.groovy.control.CompilationUnit.applyToPrimaryClassNodes( CompilationUnit.java:844) at org.codehaus.groovy.control.CompilationUnit.classgen(CompilationUnit. java:540) at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.j ava:446)

          People

          • Assignee:
            Guillaume Laforge
            Reporter:
            Doug Bryant
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: