Spring Tool Suite
  1. Spring Tool Suite
  2. STS-2465

Inconsistent warnings on imports in Grails controller unit tests

    Details

    • Type: Bug Bug
    • Status: Open Open
    • Priority: Minor Minor
    • Resolution: Unresolved
    • Affects Version/s: 2.9.0.RC2
    • Fix Version/s: None
    • Component/s: GRAILS
    • Labels:
      None

      Description

      To reproduce, create a generic grails domain class and open the generated unit test for that domain class.

      You will see the following import statements at the top and they both have warnings on them:

      import grails.test.mixin.*
      import org.junit.*
      

      The import grails.test.mixin is never used

      Then, try deleting the import statement and an error appears on the TestFor annotation and an underline under fail.

      Next, replace the imports, and the error and underling disappear. The warnings are also no longer there.

      Finally, save, make a whitespace change and re-save. The warnings come back.

      My suspicion is that the AST transform that futzes with the imports runs on a build, but not on reconciles. So after changes, the warnings will generally disappear since the imports have not been augmented.

      Possible solutions:

      1. Always run this particular AST transform, even on reconciles
      2. Do not show warnings on static or on demand import statements when they are unused

      I have also noticed a similar issue in other circumstances. I will raise new bugs for them.

        Activity

        Hide
        Brian Bonner added a comment -

        I'm seeing this issue as well.

        Imports for annotations are underlined (squiggly yellow)-- the warning says the imports aren't used. When I remove the imports, I get errors on the classes or annotations that needed the imports.

        Organize Imports doesn't appropriately place the imports in place.

        What's also weird is that the test has a package of com.blah. The class under test is in the same package, but the classes still have a red x by them and requires a specific import for the error to go away.

        Show
        Brian Bonner added a comment - I'm seeing this issue as well. Imports for annotations are underlined (squiggly yellow)-- the warning says the imports aren't used. When I remove the imports, I get errors on the classes or annotations that needed the imports. Organize Imports doesn't appropriately place the imports in place. What's also weird is that the test has a package of com.blah. The class under test is in the same package, but the classes still have a red x by them and requires a specific import for the error to go away.
        Hide
        Brian Bonner added a comment -

        Andrew, Is there anything we can do to get rid of the warnings and errors besides ignoring them?

        Show
        Brian Bonner added a comment - Andrew, Is there anything we can do to get rid of the warnings and errors besides ignoring them?

          People

          • Assignee:
            Unassigned
            Reporter:
            Andrew Eisenberg (c)
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              First Response Date: