QDox
  1. QDox
  2. QDOX-240

Enum constructors with new Object Instances or method calls fail with a parser exception

    Details

    • Type: Bug Bug
    • Status: Resolved Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 2.0-alpha
    • Fix Version/s: 2.0
    • Component/s: Parser
    • Labels:
      None
    • Environment:
      Java 6, qdox-2.0-alpha-1
    • Number of attachments :
      0

      Description

      I try to parse enumerations with constants that call a constructor/method, but it fails with a parse error.

      I'm using qdox-2.0-alpha-1. These are the two test cases that fail:

      ==========
      1. Calling a constructor:

      package simpleenum;
      
      import java.util.Date;
      
      public enum MinimalEnumExampleConstructor
      {
        D_CONSTRUCTOR(new Date());         // FAILS to be parsed
      
        private final Date date;
      
        private MinimalEnumExampleConstructor(final Date date)
        {
          this.date = date;
        }
      }
      

      Parse error: com.thoughtworks.qdox.parser.ParseException: syntax error @[7,21] in file\:/[snipped]/MinimalEnumExampleConstructor.java

      ==========
      2. Calling a method (probably the same root cause)

      package simpleenum;
      
      import java.util.Date;
      
      public enum MinimalEnumExampleMethod
      {
        D_METHOD(create());            // FAILS to be parsed
      
        private final Date date;
      
        private MinimalEnumExampleMethod(final Date date)
        {
          this.date = date;
        }
      
        public static Date create()
        {
          return new Date();
        }
      }
      

      Parse error: com.thoughtworks.qdox.parser.ParseException: syntax error @[7,19] in file\:/[snipped]/MinimalEnumExampleMethod.java
      ==========

      If I define a constant (e.g. for the Date instance above), the parsing completes successfully:

      public enum EnumExample ... {
        D_CONSTANT(X.Y);       // parsing successful
       ...
      }
      
      public class X {
        public static final Date Y = new Date();
      }
      

      SUCCESS

        Activity

        Robert Scholte made changes -
        Field Original Value New Value
        Description I try to parse enumerations with constants that call a constructor/method, but it fails with a parse error.

        I'm using qdox-2.0-alpha-1. These are the two test cases that fail:

        ==========
        1. Calling a constructor:

        package simpleenum;

        import java.util.Date;

        public enum MinimalEnumExampleConstructor
        {
          D_CONSTRUCTOR(new Date()); // FAILS to be parsed

          private final Date date;

          private MinimalEnumExampleConstructor(final Date date)
          {
            this.date = date;
          }
        }

        Parse error: com.thoughtworks.qdox.parser.ParseException: syntax error @[7,21] in file:/[snipped]/MinimalEnumExampleConstructor.java

        ==========
        2. Calling a method (probably the same root cause)

        package simpleenum;

        import java.util.Date;

        public enum MinimalEnumExampleMethod
        {
          D_METHOD(create()); // FAILS to be parsed

          private final Date date;

          private MinimalEnumExampleMethod(final Date date)
          {
            this.date = date;
          }

          public static Date create()
          {
            return new Date();
          }
        }

        Parse error: com.thoughtworks.qdox.parser.ParseException: syntax error @[7,19] in file:/[snipped]/MinimalEnumExampleMethod.java
        ==========



        If I define a constant (e.g. for the Date instance above), the parsing completes successfully:

        public enum EnumExample ... {
          D_CONSTANT(X.Y); // parsing successful
         ...
        }

        public class X {
          public static final Date Y = new Date();
        }

        SUCCESS

        I try to parse enumerations with constants that call a constructor/method, but it fails with a parse error.

        I'm using qdox-2.0-alpha-1. These are the two test cases that fail:

        ==========
        1. Calling a constructor:
        {code}
        package simpleenum;

        import java.util.Date;

        public enum MinimalEnumExampleConstructor
        {
          D_CONSTRUCTOR(new Date()); // FAILS to be parsed

          private final Date date;

          private MinimalEnumExampleConstructor(final Date date)
          {
            this.date = date;
          }
        }
        {code}
        {{Parse error: com.thoughtworks.qdox.parser.ParseException: syntax error @\[7,21\] in file\:/\[snipped\]/MinimalEnumExampleConstructor.java}}

        ==========
        2. Calling a method (probably the same root cause)
        {code}
        package simpleenum;

        import java.util.Date;

        public enum MinimalEnumExampleMethod
        {
          D_METHOD(create()); // FAILS to be parsed

          private final Date date;

          private MinimalEnumExampleMethod(final Date date)
          {
            this.date = date;
          }

          public static Date create()
          {
            return new Date();
          }
        }
        {code}
        {{Parse error: com.thoughtworks.qdox.parser.ParseException: syntax error @\[7,19\] in file\:/\[snipped\]/MinimalEnumExampleMethod.java}}
        ==========



        If I define a constant (e.g. for the Date instance above), the parsing completes successfully:
        {code}
        public enum EnumExample ... {
          D_CONSTANT(X.Y); // parsing successful
         ...
        }

        public class X {
          public static final Date Y = new Date();
        }
        {code}
        {{SUCCESS}}

        Hide
        Robert Scholte added a comment -

        With rev. 1492 rev. 1493 the parsing problems of the testcases have been solved.
        I still have to make them part of the model, so sources can be regenerated.
        I leave this issue open until that is fixed too.

        Show
        Robert Scholte added a comment - With rev. 1492 rev. 1493 the parsing problems of the testcases have been solved. I still have to make them part of the model, so sources can be regenerated. I leave this issue open until that is fixed too.
        Hide
        Pei-Tang Huang added a comment -

        Generic type make Enum construction parsing fail too:

        import java.util.HashMap;
        
        public enum MyEnum {
            MAP(new HashMap<String, Object>()); // Parser throws java.util.EmptyStackException
            
            public final Object defaultValue;
            
            private ClassEnum(Object defaultValue) {
                this.defaultValue = defaultValue;
            }
        }
        

        The exception caused by parser.y:352:

        TypeArguments: LESSTHAN 
                       {
                         typeStack.peek().setActualArgumentTypes(new LinkedList<TypeDef>());
                       }
                       _TypeArgumentList GREATERTHAN
                     ;
        
        Show
        Pei-Tang Huang added a comment - Generic type make Enum construction parsing fail too: import java.util.HashMap; public enum MyEnum { MAP( new HashMap< String , Object >()); // Parser throws java.util.EmptyStackException public final Object defaultValue; private ClassEnum( Object defaultValue) { this .defaultValue = defaultValue; } } The exception caused by parser.y:352: TypeArguments: LESSTHAN { typeStack.peek().setActualArgumentTypes( new LinkedList<TypeDef>()); } _TypeArgumentList GREATERTHAN ;
        Hide
        Robert Scholte added a comment -

        Fixed in rev.1574

        Show
        Robert Scholte added a comment - Fixed in rev.1574
        Robert Scholte made changes -
        Resolution Fixed [ 1 ]
        Fix Version/s 2.0 [ 15636 ]
        Assignee Robert Scholte [ rfscholte ]
        Status Open [ 1 ] Resolved [ 5 ]

          People

          • Assignee:
            Robert Scholte
            Reporter:
            Robert Reiner
          • Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: