RC-12 Implement rule S2654: JEE applications should not use threads or synchronization#5702
RC-12 Implement rule S2654: JEE applications should not use threads or synchronization#5702NoemieBenard wants to merge 4 commits into
Conversation
| private void handleMethod(MethodTree method) { | ||
| ModifierKeywordTree syncModifier = ModifiersUtils.getModifier(method.modifiers(), Modifier.SYNCHRONIZED); | ||
| if (syncModifier != null && (JEE_SERVLET_MATCHER.matches(method) || isEjbAnnotated(method))) { | ||
| reportIssue(syncModifier, SYNCHRONIZED_ISSUE_MESSAGE); | ||
| } | ||
| } | ||
|
|
||
| private static boolean isEjbAnnotated(MethodTree method) { | ||
| SymbolMetadata metadata = Objects.requireNonNull(method.symbol().enclosingClass()).metadata(); | ||
| return EJB_ANNOTATIONS.stream().anyMatch(metadata::isAnnotatedWith); | ||
| } |
There was a problem hiding this comment.
💡 Bug: isEjbAnnotated path for synchronized methods is never tested
handleMethod flags synchronized methods either when JEE_SERVLET_MATCHER.matches(method) (servlet) or when isEjbAnnotated(method) is true. The test samples (JEEThreadCheckSample.java / JEEThreadCheckJakartaSample.java) only contain a synchronized method (syncMethod) inside the servlet classes, exercising the matcher branch. The EJB classes (Stateless/Stateful/Singleton/MessageDriven) only contain a synchronized block and a Runnable — none has a synchronized method. As a result the isEjbAnnotated branch in handleMethod, including the Objects.requireNonNull(method.symbol().enclosingClass()) call, is never covered by tests. Add a public synchronized void m() {} to at least one EJB sample class (and verify it is flagged Noncompliant) to cover this branch.
Was this helpful? React with 👍 / 👎
| private static boolean isInJeeClass(Tree tree) { | ||
| Tree current = tree.is(Tree.Kind.CLASS) ? tree.parent() : tree; | ||
| while (current != null) { | ||
| if (current.is(Tree.Kind.CLASS)) { | ||
| return isJeeClass((ClassTree) current); | ||
| } | ||
| current = current.parent(); | ||
| } | ||
| return false; | ||
| } |
There was a problem hiding this comment.
💡 Edge Case: JEE component implementing Runnable directly is not flagged
isInJeeClass for a CLASS node starts the search at tree.parent(), so it checks only the enclosing class, never the class itself. Consequently a JEE component that directly implements Runnable (e.g. @Stateless class Foo implements Runnable { public void run(){} }) is not reported, because the search skips Foo and finds no enclosing JEE class. Similarly, a Runnable declared inside a non-JEE inner class nested within a servlet/EJB is not flagged, since only the first enclosing class is inspected. If these are intended out-of-scope cases it would be worth adding a Compliant/Noncompliant test documenting the behavior; otherwise consider checking the class itself and/or walking all enclosing classes.
Was this helpful? React with 👍 / 👎
CI failed: The CI build encountered a transient 429 dependency resolution error and a series of end-to-end test timeouts. The Playwright UI tests failed due to resource contention or environment instability rather than the specific code changes in the PR.OverviewTwo primary failure patterns were identified across the CI runs: a transient dependency resolution error in the build phase and multiple E2E test timeouts. Overall, the build is blocked by infrastructure instability and test flakiness. FailuresDependency Resolution (429 Too Many Requests) (confidence: high)
Playwright End-to-End Test Timeouts (confidence: high)
Summary
Code Review 👍 Approved with suggestions 0 resolved / 2 findingsImplements rule S2654 to detect forbidden thread and synchronization usage in JEE applications. The implementation requires additional test coverage for synchronized methods in EJB-annotated classes and updated detection logic for JEE components implementing Runnable directly. 💡 Bug: isEjbAnnotated path for synchronized methods is never tested📄 java-checks/src/main/java/org/sonar/java/checks/JEEThreadCheck.java:94-104 📄 java-checks-test-sources/default/src/main/java/checks/JEEThreadCheckSample.java:48-62
💡 Edge Case: JEE component implementing Runnable directly is not flagged📄 java-checks/src/main/java/org/sonar/java/checks/JEEThreadCheck.java:106-115 📄 java-checks/src/main/java/org/sonar/java/checks/JEEThreadCheck.java:71-80
🤖 Prompt for agentsTip Comment OptionsAuto-apply is off → Gitar will not commit updates to this branch. Comment with these commands to change:
Was this helpful? React with 👍 / 👎 | Gitar |
|




No description provided.