Uploaded image for project: 'Spring Roo'
  1. Spring Roo
  2. ROO-1471

JavaParserMethodMetadata.addMethod doesn't add 'throw exception list' to new method.

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Minor
    • Resolution: Complete
    • Affects Version/s: 1.1.0.M1
    • Fix Version/s: 1.1.0.RC1
    • Component/s: @ CORE
    • Labels:
      None
    • Environment:
      SUN JDK 1.5.0_07
      Ubuntu 10.04
      Eclipse 3.5.1

      Description

      Hi!
      Creation of a new method to a class using JavaParserMethodMetadata.addMethod(...) only adds throws type list when parameter list is not empty because // Add exceptions which the method my throw code is inside parameter list loop.

      JavaParserMethodMetadata.java
      // Lines 259-268
      // Add exceptions which the method my throw
      if (method.getThrowsTypes().size() > 0) {
      	List<NameExpr> throwsTypes = new ArrayList<NameExpr>();
      	for (JavaType javaType: method.getThrowsTypes()) {
      		NameExpr importedType = JavaParserUtils.importTypeIfRequired(compilationUnitServices.getEnclosingTypeName(), compilationUnitServices.getImports(), javaType);
      		throwsTypes.add(importedType);
      	}
      	d.setThrows(throwsTypes);
      }
      

      It must be checked outside parameter loop in JavaParserMethodMetadata.addMethod(...).
      And if create a method with parameters and you add a List of JavaTypes that don't extend java.lang.Exception or java.lang.Throwable as throwsTypes variable in MethodMetadata (i.e. java.lang.Long), the method is created anyway without errors (in ROO console) but in the project exists compiling errors because this is not an Exception class declared to be thrown.

      Thanks!

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              balex Ben Alex
              Reporter:
              ricardogarfe Ricardo GarcĂ­a
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: