Skip to content

Instantly share code, notes, and snippets.

View sebastianmonte's full-sized avatar

Sebastian Monte sebastianmonte

View GitHub Profile
@sebastianmonte
sebastianmonte / DivZero.java
Created February 12, 2015 13:30
DivZero Bug Checker
public class DivZero extends BugChecker
implements BinaryTreeMatcher, CompoundAssignmentTreeMatcher {
@Override
public Description matchBinary(BinaryTree tree, VisitorState state) {
return matchDivZero(tree, tree.getRightOperand(), state);
}
@Override
public Description matchCompoundAssignment(CompoundAssignmentTree tree, VisitorState state) {
@sebastianmonte
sebastianmonte / pom.xml
Created February 12, 2015 13:35
Maven and Error Prone
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.2</version>
<configuration>
<compilerId>javac-with-errorprone</compilerId>
<forceJavacCompilerUse>true</forceJavacCompilerUse>
<source>1.7</source>
<target>1.7</target>
</configuration>
@sebastianmonte
sebastianmonte / output
Created February 12, 2015 13:36
Error Prone Compilation Errors
[WARNING] COMPILATION WARNING :
[INFO] -------------------------------------------------------------
[WARNING] /IdeaProjects/elasticsearch/src/main/java/jsr166e/Striped64.java:[98,38] sun.misc.Unsafe is internal proprietary API and may be removed in a future release
[WARNING] /IdeaProjects/elasticsearch/src/main/java/jsr166e/Striped64.java:[296,34] sun.misc.Unsafe is internal proprietary API and may be removed in a future release
[WARNING] /IdeaProjects/elasticsearch/src/main/java/jsr166e/Striped64.java:[319,28] sun.misc.Unsafe is internal proprietary API and may be removed in a future release
[WARNING] /IdeaProjects/elasticsearch/src/main/java/jsr166e/Striped64.java:[321,28] sun.misc.Unsafe is internal proprietary API and may be removed in a future release
[WARNING] /IdeaProjects/elasticsearch/src/main/java/jsr166e/Striped64.java:[325,66] sun.misc.Unsafe is internal proprietary API and may be removed in a future release
[WARNING] /IdeaProjects/elasticsearch/src/main/java/jsr166e/Striped64.java:[326,32] sun.m
@sebastianmonte
sebastianmonte / checkreturnvalue
Created February 12, 2015 13:37
Check Return Value Error
[ERROR] /IdeaProjects/elasticsearch/src/main/java/org/elasticsearch/script/ScriptService.java:[247,37] [CheckReturnValue] Ignored return value of method that is annotated with @CheckReturnValue
(see http://code.google.com/p/error-prone/wiki/CheckReturnValue)
Did you mean 'cacheBuilder = cacheBuilder.removalListener(new ScriptCacheRemovalListener());'?
@sebastianmonte
sebastianmonte / CheckReturnValueFix.java
Created February 12, 2015 13:38
Fix for Check Return Value
// OLD
cacheBuilder.removalListener(new ScriptCacheRemovalListener());
this.cache = cacheBuilder.build();
// NEW
cacheBuilder = cacheBuilder.removalListener(new ScriptCacheRemovalListener())
this.cache = cacheBuilder.build();
@sebastianmonte
sebastianmonte / CheckReturnValueFixOneLiner.java
Created February 12, 2015 13:38
Check Return Value Fix One Liner
this.cache = cacheBuilder.removalListener(new ScriptCacheRemovalListener()).build();
@sebastianmonte
sebastianmonte / staticaccessedfrominstanc
Created February 12, 2015 13:47
Static Accessed from Instance
[ERROR] /IdeaProjects/elasticsearch/src/main/java/org/elasticsearch/indices/recovery/ShardRecoveryHandler.java:[229,48] [StaticAccessedFromInstance] A static variable or method should not be accessed from an instance
(see http://code.google.com/p/error-prone/wiki/StaticAccessedFromInstance)
Did you mean 'if (fileSize > RecoverySettings.SMALL_FILE_CUTOFF_BYTES) {'?
@sebastianmonte
sebastianmonte / StaticAccessedFromInstanceFix.java
Created February 12, 2015 13:49
Static Accessed from Instance Fix
// OLD
if (fileSize > recoverySettings.SMALL_FILE_CUTOFF_BYTES) {
//NEW
if (fileSize > RecoverySettings.SMALL_FILE_CUTOFF_BYTES) {
package com.gofore.test;
import com.gofore.fixme.annotation.Fixme;
import java.util.List;
public class NumberAdder {
@Fixme(summary = "Use stream instead of loop")
public static int add(List<Integer> numbers) {
package com.gofore.fixme.annotation;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import static java.lang.annotation.ElementType.*;
@Retention(RetentionPolicy.SOURCE)
@Target({ANNOTATION_TYPE, CONSTRUCTOR, FIELD, METHOD, TYPE})