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

Question : NonOverridingEquals bug pattern #1049

Closed
euwnsep1225 opened this issue Jun 6, 2018 · 1 comment
Closed

Question : NonOverridingEquals bug pattern #1049

euwnsep1225 opened this issue Jun 6, 2018 · 1 comment

Comments

@euwnsep1225
Copy link

I expected NonOverridingEquals bug pattern and compiled the code, but the results were different than I expected. so I am sending this issue because I wonder if I have run the errorprone properly.

What version of Error Prone are you using?

2.3.1

Does this issue reproduce with the latest release?

N/A

What did you do?

pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>Maven_2_Test</groupId>
  <artifactId>maven_sample</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>jar</packaging>

  <name>maven_sample</name>
  <url>http://maven.apache.org</url>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.complier.source>1.6</maven.complier.source>
    <maven.complier.target>1.6</maven.complier.target>
  </properties>

  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.12</version>
      <scope>test</scope>
    </dependency>
  </dependencies>
    <build>
  <plugins>
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-compiler-plugin</artifactId>
      <version>3.3</version>
      <configuration>
        <compilerId>javac-with-errorprone</compilerId>
        <forceJavacCompilerUse>true</forceJavacCompilerUse>
        <!-- maven-compiler-plugin defaults to targeting Java 5, but our javac
             only supports >=6 -->
        <source>7</source>
        <target>7</target>
      </configuration>
      <dependencies>
        <dependency>
          <groupId>org.codehaus.plexus</groupId>
          <artifactId>plexus-compiler-javac-errorprone</artifactId>
          <version>2.8.3</version>
        </dependency>
        <!-- override plexus-compiler-javac-errorprone's dependency on
             Error Prone with the latest version -->
        <dependency>
          <groupId>com.google.errorprone</groupId>
          <artifactId>error_prone_core</artifactId>
          <version>2.3.1</version>
        </dependency>
      </dependencies>
    </plugin>
  </plugins>
</build>
</project>

Example.java

public class Example {
  private int value;

  public Example(int value) {
    this.value = value;
  }

  public boolean equals(Example other) {
    return this.value == other.value;
  }

  public static void main(String[] args) {
    Example exampleA = new Example(1);
    Example exampleB = new Example(1);
    System.out.println(exampleA.equals(exampleB));
  }
}

What did you expect to see?`

(see https://errorprone.info/bugpattern/NonOverridingEquals)

What did you see instead?

euwnsep@ubuntu:~/eclipse-workspace/maven_sample$ mvn compile
[INFO] Scanning for projects...
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building maven_sample 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ maven_sample ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /home/euwnsep/eclipse-workspace/maven_sample/src/main/resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.3:compile (default-compile) @ maven_sample ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 1 source file to /home/euwnsep/eclipse-workspace/maven_sample/target/classes
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 6.816 s
[INFO] Finished at: 2018-06-06T08:33:04-07:00
[INFO] Final Memory: 20M/60M
[INFO] ------------------------------------------------------------------------
@cushon
Copy link
Collaborator

cushon commented Jan 8, 2021

Note that we don't recommend plexus-compiler-javac-errorprone anymore, this is the recommended way to use Error Prone with maven: http://errorprone.info/docs/installation#maven

That example works for me using the maven instructions above, although I have to pass -Dmaven.compiler.showWarnings to get maven to actually display the warnings:

mvn clean package -Dmaven.compiler.showWarnings=true
...
[WARNING] ./Example.java:[8,18] [NonOverridingEquals] equals method doesn't override Object.equals
    (see https://errorprone.info/bugpattern/NonOverridingEquals)
  Did you mean '@Override'?

@cushon cushon closed this as completed Jan 8, 2021
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

No branches or pull requests

2 participants