Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,17 @@
class SystemOutOrErrUsageCheckSample {

void f() {
System.out.println(""); // Noncompliant {{Replace this use of System.out by a logger.}}
System.err.println(""); // Noncompliant {{Replace this use of System.err by a logger.}}
// ^^^^^^^^^^
System.out.println("");
System.err.println("");
K.out();
K.err();


g(System.out); // Noncompliant
g(System.out);

System.arraycopy(null, 0, null, 0, 0); // Compliant
java.lang.System.out.println(""); // Noncompliant
// ^^^^^^^^^^^^^^^^^^^^
java.lang.System.out.println(""); // Noncompliant
// ^^^^^^^^^^^^^^^^^^^^
java.lang.System.out.println("");
java.lang.System.out.println("");
}

void g(PrintStream stream){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

import org.sonar.check.Rule;
import org.sonar.plugins.java.api.IssuableSubscriptionVisitor;
import org.sonar.plugins.java.api.tree.ExpressionTree;
import org.sonar.plugins.java.api.tree.IdentifierTree;
import org.sonar.plugins.java.api.tree.MemberSelectExpressionTree;
import org.sonar.plugins.java.api.tree.Tree;
Expand Down Expand Up @@ -51,26 +50,11 @@ public void visitNode(Tree tree) {
}

private void visitMemberSelectExpression(MemberSelectExpressionTree mset) {
String name = mset.identifier().name();
if ("out".equals(name) && isSystem(mset.expression())) {
reportIssue(mset, "Replace this use of System.out by a logger.");
} else if ("err".equals(name) && isSystem(mset.expression())) {
reportIssue(mset, "Replace this use of System.err by a logger.");
} else if (isIoPrintFunction(mset)) {
if (isIoPrintFunction(mset)) {
reportIssue(mset, "Replace this use of IO." + mset.identifier().name() + " by a logger.");
}
}
Comment on lines 52 to 56

@gitar-bot gitar-bot Bot Nov 20, 2026 •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Bug: S106 no longer reports System.out/err, breaking downstream SonarLint ITs

visitMemberSelectExpression now reports only when isIoPrintFunction(mset) is true, so every System.out/System.err usage, which is the core of rule S106, goes silent. The sample file and verifyNoIssues() tests were changed to match. The PR says this is a deliberate, do-not-merge regression. Even so, it should not land on romain/ap-1498 or anything downstream. Several SonarLint consumers depend on S106 firing on plain System.out: sonarlint-eclipse connected-mode ITs such as OpenInIdeTest that call getFirstIssue(S106) on SysOut.java; the sonarlint-vscode java diagnostics IT, which expects 'Replace this use of System.out by a logger.'; and sonarlint-intellij StandaloneModeMediumTests.should_analyze_java_file, which expects java:S106 on src/Main.java. All of these would fail once they bump to a sonar-java release that contains this commit. Close this PR, or revert commit 156ca76, once the ruling diff action has been exercised, and keep it out of the #6550 stack before that merges.

Restore the original System.out/System.err reporting branch alongside the IO.print branch:

private void visitMemberSelectExpression(MemberSelectExpressionTree mset) {
  if (isIoPrintFunction(mset)) {
    reportIssue(mset, "Replace this use of IO." + mset.identifier().name() + " by a logger.");
    return;
  }
  String name = mset.identifier().name();
  if (("out".equals(name) || "err".equals(name)) && isSystem(mset.expression())) {
    reportIssue(mset, "Replace this use of System." + name + " by a logger.");
  }
}

Was this helpful? React with 👍 / 👎

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed that this behavior must not ship. PR #6551 is a draft test branch created solely to produce an S106 ruling diff; the production branch (#6550) retains normal System.out/System.err reporting. I fixed the separate PR-head checkout failure and will close this test PR after the ruling diff action runs.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Understood. The finding holds on this branch (SystemOutOrErrUsageCheck only reports when isIoPrintFunction(mset) is true), and you've confirmed it's intentional for this throwaway ruling-diff PR. I've recorded it as won't fix and made no code changes. Just make sure #6551 is closed rather than merged, so it doesn't reach #6550 or any SonarLint consumers.


private static boolean isSystem(ExpressionTree expression) {
IdentifierTree identifierTree = null;
if (expression.is(Tree.Kind.IDENTIFIER)) {
identifierTree = (IdentifierTree) expression;
} else if (expression.is(Tree.Kind.MEMBER_SELECT)) {
identifierTree = ((MemberSelectExpressionTree) expression).identifier();
}
return identifierTree != null && "System".equals(identifierTree.name());
}

private static boolean isIoPrintFunction(MemberSelectExpressionTree mset) {
boolean isIoFunction = mset.expression().parent() instanceof MemberSelectExpressionTree tree &&
tree.expression() instanceof IdentifierTree identifierTree &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ void test_sout() {
CheckVerifier.newVerifier()
.onFile(mainCodeSourcesPath("checks/SystemOutOrErrUsageCheckSample.java"))
.withCheck(new SystemOutOrErrUsageCheck())
.verifyIssues();
.verifyNoIssues();
}

@Test
Expand Down Expand Up @@ -69,6 +69,6 @@ void test_without_semantic() {
.onFile(mainCodeSourcesPath("checks/SystemOutOrErrUsageCheckSample.java"))
.withCheck(new SystemOutOrErrUsageCheck())
.withoutSemantic()
.verifyIssues();
.verifyNoIssues();
}
}
Loading