Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[EC2] Avoid multiple if-else statement : java.lang.ClassCastException #9

Closed
anolf opened this issue Jan 24, 2024 · 2 comments · Fixed by #10
Closed

[EC2] Avoid multiple if-else statement : java.lang.ClassCastException #9

anolf opened this issue Jan 24, 2024 · 2 comments · Fixed by #10

Comments

@anolf
Copy link

anolf commented Jan 24, 2024

Error :
[�[1;31mERROR�[m] Unable to run check class fr.greencodeinitiative.java.checks.AvoidMultipleIfElseStatement - EC2 on file 'src/main/.../GridLayout.java', To help improve the SonarSource Java Analyzer, please report this problem to SonarSource: see https://community.sonarsource.com/
java.lang.ClassCastException: class org.sonar.java.model.statement.ReturnStatementTreeImpl cannot be cast to class org.sonar.plugins.java.api.tree.BlockTree (org.sonar.java.model.statement.ReturnStatementTreeImpl and org.sonar.plugins.java.api.tree.BlockTree are in unnamed module of loader org.sonar.classloader.ClassRealm @35a9e665)
at fr.greencodeinitiative.java.checks.AvoidMultipleIfElseStatement.visitIfNode(AvoidMultipleIfElseStatement.java:118)
at fr.greencodeinitiative.java.checks.AvoidMultipleIfElseStatement.visitNodeContent(AvoidMultipleIfElseStatement.java:95)
at fr.greencodeinitiative.java.checks.AvoidMultipleIfElseStatement.visitNode(AvoidMultipleIfElseStatement.java:75)
at org.sonar.java.model.VisitorsBridge$IssuableSubscriptionVisitorsRunner.lambda$visit$6(VisitorsBridge.java:452)
at org.sonar.java.model.VisitorsBridge$IssuableSubscriptionVisitorsRunner.lambda$forEach$9(VisitorsBridge.java:468)
at org.sonar.java.model.VisitorsBridge.runScanner(VisitorsBridge.java:265)
at org.sonar.java.model.VisitorsBridge$IssuableSubscriptionVisitorsRunner.forEach(VisitorsBridge.java:468)
at org.sonar.java.model.VisitorsBridge$IssuableSubscriptionVisitorsRunner.visit(VisitorsBridge.java:454)
at org.sonar.java.model.VisitorsBridge$IssuableSubscriptionVisitorsRunner.visitChildren(VisitorsBridge.java:438)
at org.sonar.java.model.VisitorsBridge$IssuableSubscriptionVisitorsRunner.visit(VisitorsBridge.java:458)
at org.sonar.java.model.VisitorsBridge$IssuableSubscriptionVisitorsRunner.visitChildren(VisitorsBridge.java:438)
at org.sonar.java.model.VisitorsBridge$IssuableSubscriptionVisitorsRunner.visit(VisitorsBridge.java:458)
at org.sonar.java.model.VisitorsBridge$IssuableSubscriptionVisitorsRunner.scanFile(VisitorsBridge.java:416)
at org.sonar.java.model.VisitorsBridge.lambda$runScanner$1(VisitorsBridge.java:260)
at org.sonar.java.model.VisitorsBridge.runScanner(VisitorsBridge.java:265)
at org.sonar.java.model.VisitorsBridge.runScanner(VisitorsBridge.java:260)
at org.sonar.java.model.VisitorsBridge.visitFile(VisitorsBridge.java:243)
at org.sonar.java.ast.JavaAstScanner.simpleScan(JavaAstScanner.java:132)
at org.sonar.java.JavaFrontend.scanAsBatchCallback(JavaFrontend.java:246)
at org.sonar.java.JavaFrontend.lambda$scanBatch$0(JavaFrontend.java:237)
at org.sonar.java.model.JParserConfig$Batch$1.acceptAST(JParserConfig.java:181)
at org.eclipse.jdt.core.dom.CompilationUnitResolver.resolve(CompilationUnitResolver.java:1143)
at org.eclipse.jdt.core.dom.CompilationUnitResolver.resolve(CompilationUnitResolver.java:739)
at org.eclipse.jdt.core.dom.ASTParser.createASTs(ASTParser.java:1049)
at org.sonar.java.model.JParserConfig$Batch.parse(JParserConfig.java:165)
at org.sonar.java.JavaFrontend.scanBatch(JavaFrontend.java:237)
at org.sonar.java.JavaFrontend.scanInBatches(JavaFrontend.java:227)
at org.sonar.java.JavaFrontend.scanAsBatch(JavaFrontend.java:194)
at org.sonar.java.JavaFrontend.scan(JavaFrontend.java:169)
at org.sonar.plugins.java.JavaSensor.execute(JavaSensor.java:115)
at org.sonar.scanner.sensor.AbstractSensorWrapper.analyse(AbstractSensorWrapper.java:64)
at org.sonar.scanner.sensor.ModuleSensorsExecutor.execute(ModuleSensorsExecutor.java:88)
at org.sonar.scanner.sensor.ModuleSensorsExecutor.lambda$execute$1(ModuleSensorsExecutor.java:61)
at org.sonar.scanner.sensor.ModuleSensorsExecutor.withModuleStrategy(ModuleSensorsExecutor.java:79)
at org.sonar.scanner.sensor.ModuleSensorsExecutor.execute(ModuleSensorsExecutor.java:61)
at org.sonar.scanner.scan.SpringModuleScanContainer.doAfterStart(SpringModuleScanContainer.java:82)
at org.sonar.core.platform.SpringComponentContainer.startComponents(SpringComponentContainer.java:201)
at org.sonar.core.platform.SpringComponentContainer.execute(SpringComponentContainer.java:180)
at org.sonar.scanner.scan.SpringProjectScanContainer.scan(SpringProjectScanContainer.java:398)
at org.sonar.scanner.scan.SpringProjectScanContainer.scanRecursively(SpringProjectScanContainer.java:394)
at org.sonar.scanner.scan.SpringProjectScanContainer.doAfterStart(SpringProjectScanContainer.java:363)
at org.sonar.core.platform.SpringComponentContainer.startComponents(SpringComponentContainer.java:201)
at org.sonar.core.platform.SpringComponentContainer.execute(SpringComponentContainer.java:180)
at org.sonar.scanner.bootstrap.SpringGlobalContainer.doAfterStart(SpringGlobalContainer.java:139)
at org.sonar.core.platform.SpringComponentContainer.startComponents(SpringComponentContainer.java:201)
at org.sonar.core.platform.SpringComponentContainer.execute(SpringComponentContainer.java:180)
at org.sonar.batch.bootstrapper.Batch.doExecute(Batch.java:71)
at org.sonar.batch.bootstrapper.Batch.execute(Batch.java:65)
at org.sonarsource.scanner.api.internal.batch.BatchIsolatedLauncher.execute(BatchIsolatedLauncher.java:46)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:568)
at org.sonarsource.scanner.api.internal.IsolatedLauncherProxy.invoke(IsolatedLauncherProxy.java:60)
at jdk.proxy3/jdk.proxy3.$Proxy24.execute(Unknown Source)
at org.sonarsource.scanner.api.EmbeddedScanner.doExecute(EmbeddedScanner.java:189)
at org.sonarsource.scanner.api.EmbeddedScanner.execute(EmbeddedScanner.java:138)
at org.sonarsource.scanner.maven.bootstrap.ScannerBootstrapper.execute(ScannerBootstrapper.java:64)
at org.sonarsource.scanner.maven.SonarQubeMojo.execute(SonarQubeMojo.java:108)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:137)
at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute2(MojoExecutor.java:370)
at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute(MojoExecutor.java:351)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:215)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:171)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:163)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:117)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:81)
at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:56)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:298)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:192)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:105)
at org.apache.maven.cli.MavenCli.execute(MavenCli.java:960)
at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:293)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:196)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:568)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:282)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:225)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:406)
at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:347)

To Reproduce
mvn sonar:sonar -Dmaven.test.failure.ignore=true

File contents (I think it's the "equals" method) :
package com.qualiac.ng.entity.metadata.layout;

import java.io.Serializable;

import com.qualiac.ng.entity.interfaces.ILayout;

public class GridLayout implements Serializable, ILayout {

private static final long serialVersionUID = -627909359433523933L;

// The grid-template-columns CSS property defines the line names and track sizing functions of the grid columns
private String columns = "";
// The grid-template-rows CSS property defines the line names and track sizing functions of the grid rows.
private String rows = "";
// The column-gap CSS property sets the size of the gap (gutter) between an element's columns.
private String columnGap = "0px";
// The row-gap CSS property sets the size of the gap (gutter) between an element's rows.
private String rowGap = "0px";
// The CSS justify-items property defines the default justify-self for all items of the box, giving them all a default way of justifying each box along the appropriate axis.
private String justifyItems = "auto";
// The CSS align-items property sets the align-self value on all direct children as a group. In Grid Layout it controls the alignment of items on the Block Axis within their grid area.
private String alignItems = "auto";
// The grid-template-areas CSS property specifies named grid areas.
private String templateAreas = "initial";

public String getColumns() {
    return columns;
}

public void setColumns(String columns) {
    this.columns = columns;
}

public String getRows() {
    return rows;
}

public void setRows(String rows) {
    this.rows = rows;
}

public String getColumnGap() {
    return columnGap;
}

public void setColumnGap(String columnGap) {
    this.columnGap = columnGap;
}

public String getRowGap() {
    return rowGap;
}

public void setRowGap(String rowGap) {
    this.rowGap = rowGap;
}

public String getJustifyItems() {
    return justifyItems;
}

public void setJustifyItems(String justifyItems) {
    this.justifyItems = justifyItems;
}

public String getAlignItems() {
    return alignItems;
}

public void setAlignItems(String alignItems) {
    this.alignItems = alignItems;
}

public String getTemplateAreas() {
    return templateAreas;
}

public void setTemplateAreas(String templateAreas) {
    this.templateAreas = templateAreas;
}

@Override
public int hashCode() {
    final int prime = 31;
    int result = 1;
    result = prime * result + ((alignItems == null) ? 0 : alignItems.hashCode());
    result = prime * result + ((columnGap == null) ? 0 : columnGap.hashCode());
    result = prime * result + ((columns == null) ? 0 : columns.hashCode());
    result = prime * result + ((justifyItems == null) ? 0 : justifyItems.hashCode());
    result = prime * result + ((rowGap == null) ? 0 : rowGap.hashCode());
    result = prime * result + ((rows == null) ? 0 : rows.hashCode());
    result = prime * result + ((templateAreas == null) ? 0 : templateAreas.hashCode());
    return result;
}

@Override
public boolean equals(Object obj) {
    if (this == obj)
        return true;
    if (obj == null)
        return false;
    if (getClass() != obj.getClass())
        return false;
    GridLayout other = (GridLayout) obj;
    if (alignItems == null) {
        if (other.alignItems != null)
            return false;
    } else if (!alignItems.equals(other.alignItems))
        return false;
    if (columnGap == null) {
        if (other.columnGap != null)
            return false;
    } else if (!columnGap.equals(other.columnGap))
        return false;
    if (columns == null) {
        if (other.columns != null)
            return false;
    } else if (!columns.equals(other.columns))
        return false;
    if (justifyItems == null) {
        if (other.justifyItems != null)
            return false;
    } else if (!justifyItems.equals(other.justifyItems))
        return false;
    if (rowGap == null) {
        if (other.rowGap != null)
            return false;
    } else if (!rowGap.equals(other.rowGap))
        return false;
    if (rows == null) {
        if (other.rows != null)
            return false;
    } else if (!rows.equals(other.rows))
        return false;
    if (templateAreas == null) {
        return other.templateAreas == null;
    } else
        return templateAreas.equals(other.templateAreas);
}

}

Software Versions

SonarQube Version: 10.3.0.82913
Plugin Version: 1.5.1
@dedece35 dedece35 linked a pull request Jan 24, 2024 that will close this issue
@dedece35
Copy link
Member

Hi @anolf,
thank you again for issue.
the correction is ok on linked PR.
I will create a new release 1.5.2 with this correction

@dedece35
Copy link
Member

Hi @anolf,
release 1.5.2 ready on release page.
you can test it again.
thank you.

jycr pushed a commit to jycr/ecoCode-java that referenced this issue Aug 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants