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

FindOverridableMethodCall.visitBootstrapMethods(BootstrapMethods) contains invisible \u200b character #1903

Closed
iloveeclipse opened this issue Jan 5, 2022 · 2 comments
Assignees
Labels
3rd party bug Bug in 3rd party code bug

Comments

@iloveeclipse
Copy link
Member

iloveeclipse commented Jan 5, 2022

I'm unable to compile current spotbugs code in Eclipse because of FindOverridableMethodCall.visitBootstrapMethods(BootstrapMethods) method.

The method ends with \u200b unicode character and Eclipse compiler assumes that this method can't override the visitBootstrapMethods defined in the org.apache.bcel.classfile.Visitor.visitBootstrapMethods(BootstrapMethods).

The method was added in #1716.

I will push a patch to remove the invisible character and will investigate which compiler is right.
I see that Eclipse 4.12 - 4.22 accepts \u200b in source file and preserves as part of the method name in the class file.
However, javac 1.8 - 17 accepts \u200b in the source file but does not preserve it as part of the method name in the class file.

Reported bug against ecj compiler: https://bugs.eclipse.org/bugs/show_bug.cgi?id=578063

@iloveeclipse iloveeclipse changed the title FindOverridableMethodCall.visitBootstrapMethods(BootstrapMethods) contains invisible \u200b characters FindOverridableMethodCall.visitBootstrapMethods(BootstrapMethods) contains invisible \u200b character Jan 5, 2022
@iloveeclipse iloveeclipse self-assigned this Jan 5, 2022
@iloveeclipse iloveeclipse added bug 3rd party bug Bug in 3rd party code labels Jan 5, 2022
@iloveeclipse
Copy link
Member Author

iloveeclipse commented Jan 5, 2022

Patch that shows the difference (just run it on command line)

diff --git a/spotbugs/src/main/java/edu/umd/cs/findbugs/detect/FindOverridableMethodCall.java b/spotbugs/src/main/java/edu/umd/cs/findbugs/detect/FindOverridableMethodCall.java
index b96fe8b..d1f87de 100644
--- a/spotbugs/src/main/java/edu/umd/cs/findbugs/detect/FindOverridableMethodCall.java
+++ b/spotbugs/src/main/java/edu/umd/cs/findbugs/detect/FindOverridableMethodCall.java
@@ -41,2 +41,3 @@
 import org.apache.bcel.classfile.Method;
+import org.apache.bcel.classfile.Visitor;
 
@@ -99,3 +100,24 @@
 
-    @Override
+    private static void printName(String mName) {
+        char[] name = mName.toCharArray();
+        System.out.println("Name: '" + mName + "'");
+        for (char c : name) {
+            System.out.println("" + c + " : " + (int) c);
+        }
+    }
+
+    public static void main(String[] args) {
+        java.lang.reflect.Method method = Arrays.asList(Visitor.class.getMethods()).stream()
+                .filter(m -> m.getName().startsWith("visitBootstrapMethods")).findFirst().get();
+        String name = method.getName();
+        printName(name);
+
+        method = Arrays.asList(FindOverridableMethodCall.class.getMethods()).stream()
+                .filter(m -> m.getName().startsWith("visitBootstrapMethods")).findFirst().get();
+        String name2 = method.getName();
+        printName(name2);
+        System.out.println("Equal names? : " + name.equals(name2));
+        System.out.println("Ends with '\\u200b' ? : " + name2.endsWith("" + '\u200b'));
+    }
+
     public void visitBootstrapMethods​(BootstrapMethods obj) {

Output in Eclipse (note the last 8203 character printed):

Name: 'visitBootstrapMethods'
v : 118
i : 105
s : 115
i : 105
t : 116
B : 66
o : 111
o : 111
t : 116
s : 115
t : 116
r : 114
a : 97
p : 112
M : 77
e : 101
t : 116
h : 104
o : 111
d : 100
s : 115
Name: 'visitBootstrapMethods​'
v : 118
i : 105
s : 115
i : 105
t : 116
B : 66
o : 111
o : 111
t : 116
s : 115
t : 116
r : 114
a : 97
p : 112
M : 77
e : 101
t : 116
h : 104
o : 111
d : 100
s : 115
​ : 8203
Equal names? : false
Ends with '\u200b' ? : true

iloveeclipse added a commit that referenced this issue Jan 5, 2022
The method ends with \u200b unicode character and Eclipse compiler
assumes that this method can't override the visitBootstrapMethods
defined in the org.apache.bcel.classfile.Visitor.visitBootstrapMethods(BootstrapMethods)

Sonce this character is invisible, it was added by mistake and should be
removed to allow SpotBugs compilation in Eclipse.

This fixes issue #1903.
iloveeclipse added a commit that referenced this issue Jan 5, 2022
The method ends with \u200b unicode character and Eclipse compiler
assumes that this method can't override the visitBootstrapMethods
defined in the
org.apache.bcel.classfile.Visitor.visitBootstrapMethods(BootstrapMethods)

Since this character is invisible, it was added by mistake and should be
removed to allow SpotBugs compilation in Eclipse.

This fixes issue #1903.
@iloveeclipse
Copy link
Member Author

This can find all non-ascii characters in java code in the repo

find -name *.java  -exec grep --color='auto' -P -n "[^[:ascii:]]" {} +
./spotbugs/src/main/java/edu/umd/cs/findbugs/detect/FindOverridableMethodCall.java:101:    public void visitBootstrapMethodsâ(BootstrapMethods obj) {
...
some other not critical code locations 
...

iloveeclipse added a commit that referenced this issue Jan 5, 2022
The method ends with \u200b unicode character and Eclipse compiler
assumes that this method can't override the visitBootstrapMethods
defined in the
org.apache.bcel.classfile.Visitor.visitBootstrapMethods(BootstrapMethods)

Since this character is invisible, it was added by mistake and should be
removed to allow SpotBugs compilation in Eclipse.

This fixes issue #1903.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3rd party bug Bug in 3rd party code bug
Projects
None yet
Development

No branches or pull requests

1 participant