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

Possible false positive in LSC_LITERAL_STRING_COMPARISON #393

Open
a-stewart opened this issue Apr 3, 2020 · 2 comments
Open

Possible false positive in LSC_LITERAL_STRING_COMPARISON #393

a-stewart opened this issue Apr 3, 2020 · 2 comments

Comments

@a-stewart
Copy link

I have a weird issue where the LSC_LITERAL_STRING_COMPARISON check is firing for this line of code:

766: String newLocale = "de_DE".equals(customer_locale) ? "fr_FR" : "de_DE";

Replacing that with just "de_DE" resolves the spotbugs warning.

Here is the result from javap -v:

42: ldc           #147                // String de_DE
44: aload_0
45: getfield      #8                  // Field customer_locale:Ljava/lang/String;
48: invokevirtual #148                // Method java/lang/String.equals:(Ljava/lang/Object;)Z
51: ifeq          59
54: ldc           #149                // String fr_FR
56: goto          61
59: ldc           #147                // String de_DE
61: astore        4
63: aload_0
...
LineNumberTable:
...
  line 766: 42
  line 767: 63

SpotBugs version: 3.1.12
sb-contrib version: 7.4.7
Java version: both OpenJDK 11.0.1+13 and Adopt OpenJDK 11.0.6+10

Happy to provide more code if needed but wanted to avoid making this initial post too large

@mebigfatguy
Copy link
Owner

it's almost certainly the ternary... spotbugs doesn't handle them all that well, specifically the first part of the ternary is

ldc #149 // String fr_FR
56: goto 61

is kind of ignored.

I'll see if i can figure something out here.

mebigfatguy added a commit that referenced this issue Apr 19, 2020
@mebigfatguy
Copy link
Owner

mebigfatguy commented Apr 19, 2020

Alright, so i pushed your code to LSC_Sample.fp363 and it doesn't show the error, with this, javap

  public java.lang.String fp393();
    descriptor: ()Ljava/lang/String;
    flags: ACC_PUBLIC
    Code:
      stack=2, locals=2, args_size=1
         0: ldc           #160                // String de_DE
         2: aload_0
         3: getfield      #162                // Field loc:Ljava/lang/String;
         6: invokevirtual #29                 // Method java/lang/String.equals:(Ljava/lang/Object;)Z
         9: ifeq          17
        12: ldc           #164                // String fr_FR
        14: goto          19
        17: ldc           #160                // String de_DE
        19: astore_1
        20: aload_1
        21: areturn

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants