S1943 is not detected

  • Operating system: Ubuntu 22.04LTS
  • IDE name and flavor/env: IntelliJ IDEA version 2022.2.3
  • SonarLint version: 7.1.1.54565

S1943 is not detected for the following snippet:

public static void main(String args[]) throws IOException, InterruptedException, AWTException, IllegalMonitorStateException
   {   
	Scanner sc = new Scanner(System.in);
	TicTacToe ge = null;
	//ge.clearScreen();

	System.out.println("Do You Want To Continue Then Press Y If No The Press Any Key");
	char yes = sc.next().charAt(0);
	if(yes == 'Y' || yes == 'y')
	{
		 //TimeUnit.SECONDS.wait(10);
		//ge.clearScreen();
		//Thread.sleep(4000);
		ge.game();
		
		
    }
   }

Scanner sc = new Scanner(System.in); should trigger a violation of S1943.

Hi! Any updates on this?

Hello @aman,

Thanks for your message. Could you please clarify which Java version you’re using?
Starting from Java 18 this rule doesn’t really make sense as the default charset was changed. You can check it here

You can read more about this here

Please, check if it’s not reporting on Java < 18, then it is a true false negative but on my side, I haven’t reproduced the issue so far.

Best,
Margarita

Hi Margarita!

Thank you for your response. I am using Java (Oracle OpenJDK) 11.0.15 as SDK on IntelliJ.

Please, check if it’s not reporting on Java < 18

What versions of Java SonarLint aims to support?

Regards,
Aman

Java Analyzer should be able to support versions 5 to 18.

That’s strange that it’s happening on Java 11. The rule should report an issue if you’re using Java 11.
Could you please set the version in SonarLint directly through sonar.java.source property? Set it to 18 (there should be no issue) and then set it to any other value like 11 or 17. The issue should appear then. After this, please, get back to me with the results.

Most likely is that your java version is not set correctly.

I am assuming this is where I need to change the settings.

I don’t see any difference after changing versions and applying them.

Thanks, @aman, Yes, looks like this is the right place.

Have you re-run the analysis after changing the version? You can also try re-starting the IDE.

A few more questions:
Do you see this issue when analyzing the whole project?
Can you reproduce it in SonarQube or SonarCloud?
Have you build the project?

Thanks,
Margarita

Hi!

I tried it with SonarQube, and it did not detect too. However, I found out why it is not being detected. S1943 is deactivated in the default quality profile. If I create another quality profile with S1943 activated, the violation is detected.

Regards,
Aman Sharma

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.