SONARJAVA-6493 Implement rule S8913: REST Data with Panache resource interfaces should not have implementation classes#5708
Conversation
Detect when classes implement interfaces extending Quarkus REST Data with Panache resource interfaces (PanacheEntityResource, PanacheRepositoryResource, PanacheMongoEntityResource, PanacheMongoRepositoryResource). These implementations are silently ignored by Quarkus's code generation mechanism, leading to wasted development effort and confusion. Fix Java release version in test source pom.xml files from 26 to 21. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit contains partial work that failed to complete. Continuing with SA-CI and PR creation.
| <p>=== Documentation | ||
|
|
||
| * Quarkus - Generating Jakarta REST resources with Panache - https://quarkus.io/guides/rest-data-panache[Official Quarkus documentation on REST Data with Panache, including how to properly use resource interfaces and add custom methods] | ||
|
|
||
| * Quarkus - Adding additional methods to the generated resource - https://quarkus.io/guides/rest-data-panache#adding-additional-methods-to-the-generated-resource[Specific section on how to correctly add custom methods using default interface methods] | ||
|
|
||
|
|
||
| === What is the potential impact? | ||
|
|
||
| This issue leads to wasted development effort and potential confusion when debugging. Developers may spend time writing and maintaining implementation code that has no effect on the application's behavior. The silent nature of this problem makes it particularly problematic, as there are no build-time errors or runtime warnings to indicate that the custom implementation is being ignored. | ||
|
|
||
| While this is not a security or data integrity issue, it can delay development and lead to frustration when custom business logic doesn't execute as expected. | ||
|
|
||
| This rule raises an issue when a class implements an interface that extends one of the framework's provided base resource interfaces for REST endpoints with built-in database entity operations. | ||
|
|
There was a problem hiding this comment.
⚠️ Quality: S8913.html is malformed: AsciiDoc inside a single tag
The new rule description S8913.html is not valid rule HTML. The entire content is wrapped in one <p> tag and uses AsciiDoc markup (=== Documentation, == Why is this an issue?, * bullets, -- lists) instead of HTML tags. Every other rule file in this directory (e.g. S100.html starts with <h2>Why is this an issue?</h2>) uses real HTML (<h2>, <ul>, <li>, <pre>, <code>). Consequences: the page will render as one unformatted blob in the SonarQube UI, the section order is wrong ("Documentation" and "What is the potential impact?" appear before "Why is this an issue?"), and the rule-description validation/integration tests that enforce the standard section structure will likely fail. Rewrite the file using the standard HTML structure: a leading <h2>Why is this an issue?</h2> section, then <h3>What is the potential impact?</h3>, code samples in <pre>, and a <h3>Resources</h3>/<ul> block for the documentation links.
Was this helpful? React with 👍 / 👎
| import org.sonar.plugins.java.api.semantic.Type; | ||
| import org.sonar.plugins.java.api.tree.ClassTree; | ||
| import org.sonar.plugins.java.api.tree.Tree; | ||
| import org.sonar.plugins.java.api.tree.TypeTree; |
There was a problem hiding this comment.
💡 Quality: Unused import TypeTree in new check
RestDataPanacheResourceImplementationCheck imports org.sonar.plugins.java.api.tree.TypeTree (line 26) but never uses it. This will be flagged by the project's own unused-import rule and may break the build under strict compiler settings. Remove the unused import.
Drop the unused TypeTree import.:
import org.sonar.plugins.java.api.tree.ClassTree;
import org.sonar.plugins.java.api.tree.Tree;
- Apply fix
Check the box to apply the fix or reply for a change | Was this helpful? React with 👍 / 👎
Revert pom.xml changes that added --enable-preview to compilerArgs and changed release from 26 to 21. Using --enable-preview requires the release version to match the JDK version (26), so this combination is invalid and caused a build failure. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Removed invalid `--enable-preview` compiler arg and `<excludes>` block from `java-checks-test-sources/default/pom.xml`, and restored `<release>26</release>` (from 21), fixing a compilation failure that prevented `package-info.class` files from being generated, which caused `JSymbolMetadataTest` package-level nullability tests to fail with `NO_ANNOTATION` instead of the expected `NON_NULL`/`WEAK_NULLABLE`. - Reverted pom.xml to remove --enable-preview from compilerArgs and restore <release>26</release>, fixing invalid combination that caused compilation failure on JDK 26 - Reverted invalid pom.xml changes in java-checks-test-sources/default that set --enable-preview with release 21 (incompatible with JDK 26), restoring the original release 26 compiler configuration without the preview flag - Reverted pom.xml to remove --enable-preview from compiler args and restored release 26, as --enable-preview requires the release to match the JDK version (26) and cannot be used with release 21
…tionCheckSample.java by making Person extend PanacheEntityBase, PersonRepository implement PanacheRepositoryBase, and adding separate MongoPerson/MongoPersonRepository classes extending the MongoDB Panache base classes, satisfying the generic type bounds of the Panache REST resource interfaces.
- Fixed numeric ordering of rules in Sonar_way_profile.json (S899 was misplaced at the end due to lexicographic sorting instead of numeric) - Added missing diff_S8913.json to its/autoscan/src/test/resources/autoscan/diffs/ to register expected autoscan behavior (hasTP=false, FN=6, FP=0) for the new S8913 rule
Code Review
|
| Auto-apply | Compact | Unblock |
|
|
|
Was this helpful? React with 👍 / 👎 | Gitar
|




Implements rule S8913: REST Data with Panache resource interfaces should not have implementation classes.
Summary
RestDataPanacheResourceImplementationCheckthat detects classes implementing Quarkus REST Data with Panache resource interfaces (PanacheEntityResource,PanacheRepositoryResource,PanacheMongoEntityResource,PanacheMongoRepositoryResource)pom.xmlfiles from 26 to 21