Skip to content

Analysis fails with InputMismatchException after Sonar and Checkstyle Update #533

@CarstenNeumannHB

Description

@CarstenNeumannHB

Sonar version: 10.7 (was 10.4)
Checkstyle sonar plugin version: 10.17.0 (was 10.12.5)

Hi,

since we upgraded Sonar and Checkstyle an exception occurs while performing the checkstyle analysis:

Console output:

[INFO] ------------- Run sensors on project
[INFO] Sensor CheckstyleSensor [checkstyle]
[INFO] Checkstyle output report: C:\Runners\gitlab-builds\06\censored\cpq-veterans-aggregator\target\sonar\checkstyle-result.xml
[INFO] Checkstyle configuration: C:\Runners\gitlab-builds\06\censored\cpq-veterans-aggregator\target\sonar\checkstyle.xml
[INFO] Checkstyle charset: windows-1252
line 30:34 token recognition error at: ''ä'
[INFO] Time spent writing ucfgs 0ms

Error message:

[ERROR] Failed to execute goal org.sonarsource.scanner.maven:sonar-maven-plugin:3.9.1.2184:sonar (default-cli) on project cpq-veterans-aggregator: Can not execute Checkstyle: Exception was thrown while processing C:\Runners\gitlab-builds\06\censored\util\sort\comparator\AbstractPipelineComparator.java: IllegalStateException occurred while parsing file C:\Runners\gitlab-builds\06\censored\util\sort\comparator\AbstractPipelineComparator.java. 28:39: mismatched input '(' expecting ';': InputMismatchException -> [Help 1]
[ERROR]

With Checkstyle the analysis on this file can be performed:

PS C:\Tools\checkstyle> java -jar '-Duser.language=en -Duser.country=US' .\checkstyle-10.17.0-all.jar -c /sun_checks.xml .\AbstractPipelineComparator.java
Starting audit...
[ERROR] C:\Tools\checkstyle.\AbstractPipelineComparator.java:1: Missing package-info.java file. [JavadocPackage]
[ERROR] C:\Tools\checkstyle.\AbstractPipelineComparator.java:13: Line is longer than 80 characters (found 82). [LineLength]
[ERROR] C:\Tools\checkstyle.\AbstractPipelineComparator.java:14: Line has trailing spaces. [RegexpSingleline]
[ERROR] C:\Tools\checkstyle.\AbstractPipelineComparator.java:15:5: Missing a Javadoc comment. [MissingJavadocMethod]
[ERROR] C:\Tools\checkstyle.\AbstractPipelineComparator.java:16: Line has trailing spaces. [RegexpSingleline]
[ERROR] C:\Tools\checkstyle.\AbstractPipelineComparator.java:18: Line has trailing spaces. [RegexpSingleline]
[ERROR] C:\Tools\checkstyle.\AbstractPipelineComparator.java:23: Line has trailing spaces. [RegexpSingleline]
[ERROR] C:\Tools\checkstyle.\AbstractPipelineComparator.java:25: Line has trailing spaces. [RegexpSingleline]
[ERROR] C:\Tools\checkstyle.\AbstractPipelineComparator.java:27:5: Class 'AbstractPipelineComparator' looks like designed for extension (can be subclassed), but the method 'prepairForCompare' does not have javadoc that explains how to do that safely. If class is not designed for extension consider making the class 'AbstractPipelineComparator' final or making the method 'prepairForCompare' static/final/abstract/empty, or adding allowed annotation for the method. [DesignForExtension]
[ERROR] C:\Tools\checkstyle.\AbstractPipelineComparator.java:27:40: Parameter o should be final. [FinalParameters]
[ERROR] C:\Tools\checkstyle.\AbstractPipelineComparator.java:29: Line has trailing spaces. [RegexpSingleline]
[ERROR] C:\Tools\checkstyle.\AbstractPipelineComparator.java:30:38: ',' is not followed by whitespace. [WhitespaceAfter]
[ERROR] C:\Tools\checkstyle.\AbstractPipelineComparator.java:31:38: ',' is not followed by whitespace. [WhitespaceAfter]
[ERROR] C:\Tools\checkstyle.\AbstractPipelineComparator.java:32:38: ',' is not followed by whitespace. [WhitespaceAfter]
[ERROR] C:\Tools\checkstyle.\AbstractPipelineComparator.java:33:38: ',' is not followed by whitespace. [WhitespaceAfter]
[ERROR] C:\Tools\checkstyle.\AbstractPipelineComparator.java:35: Line has trailing spaces. [RegexpSingleline]
Audit done.
Checkstyle ends with 16 errors.

This is the affected file:

/*
 * AbstractPipelineComparator.java
 *
 * Created on 16. Juni 2004, 14:15
 */

package com.censored.util.sort.comparator;

/**
 *
 * @author  censored
 */
public abstract class AbstractPipelineComparator implements java.util.Comparator {
    
    public abstract int compare(Object o1, Object o2);
    
    /*
     * Ersetzt in einem String (falls vorhanden) 
     * alle Umlaute (ä,ö,ü) durch (a,o,u),
     * 'ß' durch s und alle Zeichen in Kleinbuchstaben.
     * Dies ermöglicht eine genaue Sortierung eines
     * Strings.
     * 
     * @param Object o
     * @return ersetzter String 
     */
    protected String prepairForCompare(Object o) {
        String prepair = String.valueOf(o);
        prepair = prepair.toLowerCase();        
        prepair = prepair.replace('ä','a');
        prepair = prepair.replace('ö','o');
        prepair = prepair.replace('ü','u');
        prepair = prepair.replace('ß','s');
        return prepair;
    }    
}

As you can see, it contains several German umlauts. The highlighted console output as well mentions one of them.
With former versions of SonarQube and Checkstyle-Plugin this file didn't cause any problems and it hasn't been changed since.

Thanks!

Regards,
Carsten

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions