StringIndexOutOfBoundsException when analyzing my KomodoAutoConfiguration

Template for a good bug report, formatted with Markdown:

  • versions used Sonarlint for Eclipse 3.1.0
  • error observed (wrap logs/code around triple quote ``` for proper formatting)
Error during analysis
org.sonar.squidbridge.api.AnalysisException: SonarQube is unable to analyze file : '/home/apupier/git/teiid-syndesis/komodo-server/src/main/java/org/komodo/rest/KomodoAutoConfiguration.java'
	at org.sonar.java.ast.JavaAstScanner.simpleScan(JavaAstScanner.java:95)
	at org.sonar.java.ast.JavaAstScanner.scan(JavaAstScanner.java:63)
	at org.sonar.java.JavaSquid.scanSources(JavaSquid.java:119)
	at org.sonar.java.JavaSquid.scan(JavaSquid.java:113)
	at org.sonar.plugins.java.JavaSquidSensor.execute(JavaSquidSensor.java:84)
	at org.sonarsource.sonarlint.core.analyzer.sensor.SensorWrapper.analyse(SensorWrapper.java:52)
	at org.sonarsource.sonarlint.core.analyzer.sensor.SensorsExecutor.executeSensor(SensorsExecutor.java:75)
	at org.sonarsource.sonarlint.core.analyzer.sensor.SensorsExecutor.execute(SensorsExecutor.java:63)
	at org.sonarsource.sonarlint.core.analyzer.sensor.PhaseExecutor.execute(PhaseExecutor.java:44)
	at org.sonarsource.sonarlint.core.container.analysis.AnalysisContainer.doAfterStart(AnalysisContainer.java:139)
	at org.sonarsource.sonarlint.core.container.ComponentContainer.startComponents(ComponentContainer.java:125)
	at org.sonarsource.sonarlint.core.container.ComponentContainer.execute(ComponentContainer.java:110)
	at org.sonarsource.sonarlint.core.container.standalone.StandaloneGlobalContainer.analyze(StandaloneGlobalContainer.java:122)
	at org.sonarsource.sonarlint.core.StandaloneSonarLintEngineImpl.analyze(StandaloneSonarLintEngineImpl.java:96)
	at org.sonarsource.sonarlint.core.StandaloneSonarLintEngineImpl.analyze(StandaloneSonarLintEngineImpl.java:84)
	at org.sonarlint.eclipse.core.internal.jobs.StandaloneSonarLintClientFacade.runAnalysis(StandaloneSonarLintClientFacade.java:74)
	at org.sonarlint.eclipse.core.internal.jobs.AnalyzeProjectJob.run(AnalyzeProjectJob.java:474)
	at org.sonarlint.eclipse.core.internal.jobs.AnalyzeProjectJob$AnalysisThread.run(AnalyzeProjectJob.java:124)
Caused by: java.lang.StringIndexOutOfBoundsException: String index out of range: 10
	at java.lang.String.charAt(String.java:658)
	at java.util.regex.Pattern$BmpCharProperty.match(Pattern.java:3811)
	at java.util.regex.Pattern$Curly.match(Pattern.java:4241)
	at java.util.regex.Pattern$GroupHead.match(Pattern.java:4672)
	at java.util.regex.Pattern$Loop.matchInit(Pattern.java:4815)
	at java.util.regex.Pattern$Prolog.match(Pattern.java:4755)
	at java.util.regex.Pattern$GroupHead.match(Pattern.java:4672)
	at java.util.regex.Pattern$Curly.match1(Pattern.java:4301)
	at java.util.regex.Pattern$Curly.match(Pattern.java:4250)
	at java.util.regex.Matcher.match(Matcher.java:1270)
	at java.util.regex.Matcher.matches(Matcher.java:604)
	at org.sonar.java.checks.HardcodedIpCheck.visitLiteral(HardcodedIpCheck.java:50)
	at org.sonar.java.model.expression.LiteralTreeImpl.accept(LiteralTreeImpl.java:60)
	at org.sonar.java.ast.parser.ListTreeImpl.accept(ListTreeImpl.java:63)
	at org.sonar.plugins.java.api.tree.BaseTreeVisitor.scan(BaseTreeVisitor.java:43)
	at org.sonar.plugins.java.api.tree.BaseTreeVisitor.scan(BaseTreeVisitor.java:48)
	at org.sonar.plugins.java.api.tree.BaseTreeVisitor.visitMethodInvocation(BaseTreeVisitor.java:252)
	at org.sonar.java.model.expression.MethodInvocationTreeImpl.accept(MethodInvocationTreeImpl.java:96)
	at org.sonar.plugins.java.api.tree.BaseTreeVisitor.scan(BaseTreeVisitor.java:43)
	at org.sonar.plugins.java.api.tree.BaseTreeVisitor.visitReturnStatement(BaseTreeVisitor.java:173)
	at org.sonar.java.model.statement.ReturnStatementTreeImpl.accept(ReturnStatementTreeImpl.java:69)
	at org.sonar.plugins.java.api.tree.BaseTreeVisitor.scan(BaseTreeVisitor.java:43)
	at org.sonar.plugins.java.api.tree.BaseTreeVisitor.scan(BaseTreeVisitor.java:37)
	at org.sonar.plugins.java.api.tree.BaseTreeVisitor.visitBlock(BaseTreeVisitor.java:85)
	at org.sonar.java.model.statement.BlockTreeImpl.accept(BlockTreeImpl.java:77)
	at org.sonar.plugins.java.api.tree.BaseTreeVisitor.scan(BaseTreeVisitor.java:43)
	at org.sonar.plugins.java.api.tree.BaseTreeVisitor.visitMethod(BaseTreeVisitor.java:80)
	at org.sonar.java.model.declaration.MethodTreeImpl.accept(MethodTreeImpl.java:218)
	at org.sonar.plugins.java.api.tree.BaseTreeVisitor.scan(BaseTreeVisitor.java:43)
	at org.sonar.plugins.java.api.tree.BaseTreeVisitor.scan(BaseTreeVisitor.java:37)
	at org.sonar.plugins.java.api.tree.BaseTreeVisitor.visitClass(BaseTreeVisitor.java:69)
	at org.sonar.java.model.declaration.ClassTreeImpl.accept(ClassTreeImpl.java:194)
	at org.sonar.plugins.java.api.tree.BaseTreeVisitor.scan(BaseTreeVisitor.java:43)
	at org.sonar.plugins.java.api.tree.BaseTreeVisitor.scan(BaseTreeVisitor.java:37)
	at org.sonar.plugins.java.api.tree.BaseTreeVisitor.visitCompilationUnit(BaseTreeVisitor.java:55)
	at org.sonar.java.model.JavaTree$CompilationUnitTreeImpl.accept(JavaTree.java:184)
	at org.sonar.plugins.java.api.tree.BaseTreeVisitor.scan(BaseTreeVisitor.java:43)
	at org.sonar.java.checks.HardcodedIpCheck.scanFile(HardcodedIpCheck.java:43)
	at org.sonar.java.model.VisitorsBridge.visitFile(VisitorsBridge.java:111)
	at org.sonar.java.ast.JavaAstScanner.simpleScan(JavaAstScanner.java:86)
	... 17 more
  • steps to reproduce
    the file is
/*
 * Copyright Red Hat, Inc. and/or its affiliates
 * and other contributors as indicated by the @author tags and
 * the COPYRIGHT.txt file distributed with this work.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.komodo.rest;

import java.util.concurrent.ScheduledThreadPoolExecutor;

import javax.transaction.TransactionManager;
import javax.websocket.DeploymentException;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.eclipse.lsp4j.*;
import org.komodo.KEngine;
import org.komodo.lsp.TeiidDdlLanguageServer;
import org.komodo.metadata.MetadataInstance;
import org.komodo.metadata.internal.DefaultMetadataInstance;
import org.komodo.metadata.internal.TeiidServer;
import org.komodo.openshift.EncryptionComponent;
import org.komodo.openshift.TeiidOpenShiftClient;
import org.komodo.repository.WorkspaceManagerImpl;
import org.komodo.rest.connections.SyndesisConnectionSynchronizer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.ApplicationListener;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.core.task.AsyncTaskExecutor;
import org.springframework.scheduling.annotation.AsyncConfigurer;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.security.crypto.encrypt.Encryptors;
import org.springframework.security.crypto.encrypt.TextEncryptor;
import org.springframework.web.servlet.config.annotation.AsyncSupportConfigurer;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.teiid.runtime.EmbeddedConfiguration;

@Configuration
@EnableConfigurationProperties({KomodoConfigurationProperties.class, SpringMavenProperties.class})
@ComponentScan(basePackageClasses = {WorkspaceManagerImpl.class, DefaultMetadataInstance.class, SyndesisConnectionSynchronizer.class})
@EnableAsync
public class KomodoAutoConfiguration implements ApplicationListener<ContextRefreshedEvent>, AsyncConfigurer {
    private static final Log LOGGER = LogFactory.getLog(KomodoAutoConfiguration.class);

    private static final String LSP_DEFAULT_HOSTNAME = "localhost"; // syndesis-dv:????
    private static final int LSP_DEFAULT_PORT = 8025;
    private static final String LSP_DEFAULT_CONTEXT_PATH = "/";

    @Value("${encrypt.key}")
    private String encryptKey;

    @Autowired(required=false)
    private TransactionManager transactionManager;

    @Autowired
    private KomodoConfigurationProperties config;

    @Autowired
    private SpringMavenProperties maven;

    @Autowired
    private KEngine kengine;

    private TeiidDdlLanguageServer server;

    @Autowired
    private MetadataInstance metadataInstance;

    private ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor(1);

    @Bean(name = "connectionExecutor")
    public ScheduledThreadPoolExecutor connectionExecutor() {
        return executor;
    }

    @Bean
    public TextEncryptor getTextEncryptor() {
        return Encryptors.text(encryptKey, "deadbeef");
    }

    @Override
    public void onApplicationEvent(ContextRefreshedEvent event) {
        try {
            LOGGER.info("   ---->>>>>>>  KomodoAutoConfiguration.onApplicationEvent() kengine.start()");
            kengine.start();
            LOGGER.info("   ---->>>>>>>  KomodoAutoConfiguration.onApplicationEvent() initialize teiidDdlLanguageServer()");
            teiidDdlLanguageServer();
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    @Bean
    @ConditionalOnMissingBean
    public TeiidServer teiidServer() {

        // turning off PostgreSQL support
        System.setProperty("org.teiid.addPGMetadata", "false");
        System.setProperty("org.teiid.hiddenMetadataResolvable", "true");
        System.setProperty("org.teiid.allowAlter", "false");

        final TeiidServer server = new TeiidServer();

        EmbeddedConfiguration config = new EmbeddedConfiguration();
        if (this.transactionManager != null) {
            config.setTransactionManager(this.transactionManager);
        }
        server.start(config);
        return server;
    }

    @Bean
    @ConditionalOnMissingBean
    public TeiidOpenShiftClient openShiftClient(@Autowired KEngine kengine, @Autowired TextEncryptor enc) {
        return new TeiidOpenShiftClient(metadataInstance, new EncryptionComponent(enc),
                this.config, kengine, this.maven == null ? null : this.maven.getRepositories());
    }

    @Bean
    protected WebMvcConfigurer webMvcConfigurer() {
        return new WebMvcConfigurer() {
            @Override
            public void configureAsyncSupport(AsyncSupportConfigurer configurer) {
                configurer.setTaskExecutor(getAsyncExecutor());
            }
        };
    }

    @Bean
    @ConditionalOnMissingBean
    public void teiidDdlLanguageServer() {
    	
        server = new TeiidDdlLanguageServer();

        String hostname = LSP_DEFAULT_HOSTNAME;
        int port = LSP_DEFAULT_PORT;
        String contextPath = LSP_DEFAULT_CONTEXT_PATH;

        LOGGER.info("   ---->>>  KomodoAutoConfiguration.teiidDdlLanguageServer() Host:Port = " + hostname + ":" + port);

        server.startServer();

        server.getTextDocumentService();
// Server server = new Server(hostname, port, contextPath, null, MyLSPWebSocketServerConfigProvider.class);
// Runtime.getRuntime().addShutdownHook(new Thread(server::stop, "camel-lsp-websocket-server-shutdown-hook"));

// try {
// server.connect();
// Thread.currentThread().join();
// } catch (InterruptedException e) {
//
// Thread.currentThread().interrupt();
// } catch (DeploymentException e) {
//
// } finally {
// server.stop();
// }
    }

    @Override
    public AsyncTaskExecutor getAsyncExecutor() {
        ThreadPoolTaskExecutor tpte = new ThreadPoolTaskExecutor();
        tpte.initialize();
        return tpte;
    }
}

it is available here: https://github.com/blafond/teiid-syndesis/blob/teiid-lsp-prototype/komodo-server/src/main/java/org/komodo/rest/KomodoAutoConfiguration.java

  • potential workaround

P.S.: use the #bug:fault sub-category if you’re hitting a specific crash/error , or the #bug:fp sub-category for rules-related behaviour

Hello, thank you for reporting this!

SonarLint for Eclipse 3.1.0 is a very old release, more than 3 years - and according to my tests, more recent versions use a Java analyzer in which this particular issue has been fixed.

If this is possible to you, I strongly advise that you update to the most recent version which got released last week :slight_smile:

2 Likes

Hi Jean-Baptiste,

it effectively fix it.

I don’t understand why SonarLint was not updated, I apply updates regularly.

Thanks for the help

1 Like

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