Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BadImport replaces enum declarations #1653

Closed
Stephan202 opened this issue May 31, 2020 · 1 comment
Closed

BadImport replaces enum declarations #1653

Stephan202 opened this issue May 31, 2020 · 1 comment

Comments

@Stephan202
Copy link
Contributor

Consider the following code:

package foo;

import foo.Dummy.Type;

final class Dummy {
    private final Type type = Type.SIMPLE;

    enum Type {
        SIMPLE,
        COMPLEX;
    }
}

Applying the BadImport check to this code:

wget \
  https://repo1.maven.org/maven2/com/google/errorprone/error_prone_core/2.4.0/error_prone_core-2.4.0-with-dependencies.jar
javac \
  -XDcompilePolicy=simple \
  -processorpath error_prone_core-2.4.0-with-dependencies.jar \
  '-Xplugin:ErrorProne -XepPatchChecks:BadImport -XepPatchLocation:/tmp' \
  foo/Dummy.java

This yields:

--- foo/Dummy.java
+++ foo/Dummy.java
@@ -1,12 +1,12 @@
 package foo;
 
-import foo.Dummy.Type;
 
+
 final class Dummy {
-    private final Type type = Type.SIMPLE;
+    private final Dummy.Type type = Dummy.Type.SIMPLE;
 
     enum Type {
-        SIMPLE,
-        COMPLEX;
+        Dummy.SIMPLE,
+        Dummy.COMPLEX;
     }
 }

As can be seen, the Type enum declaration is now invalid.

(Related question: perhaps BadImport shouldn't flag any direct imports of types defined in the same compilation unit? That would also automatically fix this bug.)

@graememorgan
Copy link
Member

Nice finding. Sent out a fix internally.

perhaps BadImport shouldn't flag any direct imports of types defined in the same compilation unit? That would also automatically fix this bug

This seems reasonable as a heuristic to me: it shouldn't be as ambiguous within the same file.

cpovirk pushed a commit that referenced this issue Jun 10, 2020
…unit.

Fixes external #1653

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=315648656
cpovirk pushed a commit that referenced this issue Jun 10, 2020
…unit.

Fixes external #1653

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=315648656
@cushon cushon closed this as completed Jan 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants