UnsupportedOperationException with SymbolicExecutionVisitor

This is for SQ 8.9.2 with scanning through the Maven plugin.

[ERROR] Unable to run check class org.sonar.java.se.SymbolicExecutionVisitor -  on file 'MyClass.java', To help improve the SonarSource Java Analyzer, please report this problem to SonarSource: see https://community.sonarsource.com/
java.lang.UnsupportedOperationException: null
        at org.eclipse.jdt.internal.compiler.lookup.InferenceVariable.constantPoolName(InferenceVariable.java:144)
        at org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding.signature(ReferenceBinding.java:1987)
        at org.eclipse.jdt.internal.compiler.lookup.WildcardBinding.signature(WildcardBinding.java:891)
        at org.eclipse.jdt.internal.compiler.lookup.MethodBinding.signature(MethodBinding.java:1107)
        at org.eclipse.jdt.core.dom.ASTUtils.signature(ASTUtils.java:99)
        at org.sonar.java.model.JMethodSymbol.<init>(JMethodSymbol.java:67)
...

This is the redacted code in the MyClass.jave file. Sorry, someone seems to have liked generics a bit too much.

public final class MyClass {

    private MyClass() {
    }

    public static <ID extends Serializable, E extends TechnicalIdAwareEntity, R extends TechnicalIdAwareRepository<E, ID>>
    E findByTechnicalId(String technicalId, R repository) {
        verifyPreconditions(technicalId, repository);

        return repository.findByTechnicalId(technicalId).orElseThrow(
            () -> new NotFoundException(String.format("Entity not found for id '%s' in repository %s.", technicalId,
                repository.getClass().getSimpleName()), ENTITY_NOT_FOUND.getCompoundId()) {
                @Override
                public String getCode() {
                    return ENTITY_NOT_FOUND.getCompoundId();
                }
            });
    }

    public static <ID extends Serializable, E extends TechnicalIdAwareEntity, R extends TechnicalIdAwareRepository<E, ID>>
    E findByTechnicalId(String technicalId, R repository, Supplier<NotFoundException> exceptionSupplier) {
        verifyPreconditions(technicalId, repository);

        return repository.findByTechnicalId(technicalId).orElseThrow(exceptionSupplier);
    }

    private static <ID extends Serializable, E extends TechnicalIdAwareEntity, R extends TechnicalIdAwareRepository<E
        , ID>> void verifyPreconditions(String technicalId, R repository) {
        Preconditions.checkArgument(StringUtils.isNotBlank(technicalId));
        Preconditions.checkNotNull(repository);
    }
}

Reference to JDT InferenceVariable.java (master) : org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/InferenceVariable.java - jdt/eclipse.jdt.core - Gitiles

Hello @marcelstoer

I finally took the time to investigate this issue, the problem was tricky to identify since it does not come from our own code. I managed to reduce the code you provided to:

void f() {
  Optional.of("").orElseThrow(
    () -> new RuntimeException() {
      // Anonymous class
    });
}

I created a ticket to improve the situation: SONARJAVA-4127.

Finally, note that this issue is not too bad, it prevents a few rules from being executed, but the rest of the analysis should work just fine.

Thanks for taking the time to report this problem.
Best,
Quentin

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