SONARJAVA-6490 Implement S8910: Interfaces with @Mapper should have @DaoFactory methods#5690
SONARJAVA-6490 Implement S8910: Interfaces with @Mapper should have @DaoFactory methods#5690romainbrenguier wants to merge 2 commits into
Conversation
134235b to
dd242b4
Compare
54d1175 to
d2cecff
Compare
|
Add comprehensive test cases to improve code coverage: - Multi-level inheritance (interface extending interface extending base) - Multiple inheritance (interface extending multiple interfaces) - Extending unknown type (to test isUnknown branch) - Complex inheritance with mixed scenarios These additions help reach the 90% code coverage threshold required by the SonarQube quality gate. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
50364f5 to
5ad2ff5
Compare
| private static boolean hasDaoFactoryMethod(Symbol.TypeSymbol typeSymbol, Set<Symbol.TypeSymbol> visited) { | ||
| if (!visited.add(typeSymbol)) { | ||
| return false; | ||
| } | ||
|
|
||
| if (typeSymbol.memberSymbols().stream() | ||
| .filter(Symbol::isMethodSymbol) | ||
| .map(Symbol.MethodSymbol.class::cast) | ||
| .anyMatch(MapperWithoutDaoFactoryCheck::hasDaoFactoryAnnotation)) { | ||
| return true; | ||
| } | ||
|
|
||
| for (Type superType : typeSymbol.superTypes()) { | ||
| Symbol.TypeSymbol superTypeSymbol = superType.symbol(); | ||
| if (!superTypeSymbol.isUnknown() && hasDaoFactoryMethod(superTypeSymbol, visited)) { |
There was a problem hiding this comment.
💡 Edge Case: Possible false positives when @Mapper extends unresolved supertypes
In hasDaoFactoryMethod, any super type whose symbol isUnknown() is silently skipped (MapperWithoutDaoFactoryCheck.java:69-74). As a result, when a @Mapper interface extends a type that the analyzer cannot resolve (e.g. incomplete classpath, missing dependency), the check assumes the supertype contributes no @DaoFactory method and reports the interface as noncompliant. The test sample even encodes this behaviour (ExtendingNonExistentType extends UnknownType is marked Noncompliant at MapperWithoutDaoFactoryCheckSample.java:129-131). In real projects with an incomplete classpath this can produce false positives, since the unresolved supertype may actually declare the required @DaoFactory method. Consider suppressing the issue (or treating it as unknown/compliant) when the interface has at least one unresolved supertype, to avoid noisy false positives.
Was this helpful? React with 👍 / 👎
CI failed: The CI pipeline failed due to a blocking `ImportError` in the orchestration test suite and intermittent infrastructure issues downloading dependencies. The import error is caused by a missing or renamed `IngestionFolder` component, while intermittent 429 errors from package repositories are preventing successful builds.OverviewMultiple failures were detected in the CI pipeline. The primary blocker is a persistent FailuresTest Collection Failure:
|
| Auto-apply | Compact |
|
|
Was this helpful? React with 👍 / 👎 | Gitar


Summary
Implements rule S8910 to detect interfaces annotated with
@Mapperthat don't contain at least one@DaoFactorymethod.Implementation
@Mapperannotation for presence of@DaoFactorymethodsStatus
WIP - Implementation incomplete after initial attempts. Requires review and completion.
🤖 Generated with Claude Code
Summary by Gitar
Sonar_way_profile.jsonandSonar_agentic_AI_profile.json.S8910.htmlandS8910.jsonfor rule documentation and configuration.diff_S8910.jsonforautoscanverification.JavaAgenticWayProfileTestto validate the new rule integration.Mapper.javaandDaoFactory.javafor test source compilation.MapperWithoutDaoFactoryCheckSample.javacovering compliant and noncompliant scenarios.MapperWithoutDaoFactoryCheck.javaand corresponding unit tests.This will update automatically on new commits.