Summary: @public This adds an Infer model for the Integer class in Java. Test Plan: Manually inspected the specs, and added a test.master
							parent
							
								
									784c5b23d2
								
							
						
					
					
						commit
						904ebb0154
					
				@ -0,0 +1,28 @@
 | 
				
			||||
package java.lang;
 | 
				
			||||
 | 
				
			||||
public final class Integer {
 | 
				
			||||
 | 
				
			||||
  public static int MAX_VALUE = 2147483647; // 2**31-1
 | 
				
			||||
  public static int MIN_VALUE = -2147483648; // -2**31
 | 
				
			||||
 | 
				
			||||
  protected final int value;
 | 
				
			||||
 | 
				
			||||
  public Integer(int i) {
 | 
				
			||||
    this.value = i;
 | 
				
			||||
  }
 | 
				
			||||
 | 
				
			||||
  public static Integer valueOf(int i) {
 | 
				
			||||
    return new Integer(i);
 | 
				
			||||
  }
 | 
				
			||||
 | 
				
			||||
  public boolean equals(Object anObject) {
 | 
				
			||||
    return anObject != null
 | 
				
			||||
      && anObject instanceof Integer
 | 
				
			||||
      && this.value == ((Integer) anObject).value;
 | 
				
			||||
  }
 | 
				
			||||
 | 
				
			||||
  public int intValue() {
 | 
				
			||||
    return this.value;
 | 
				
			||||
  }
 | 
				
			||||
 | 
				
			||||
}
 | 
				
			||||
@ -0,0 +1,19 @@
 | 
				
			||||
import java.util.HashMap;
 | 
				
			||||
 | 
				
			||||
public class IntegerExample {
 | 
				
			||||
 | 
				
			||||
    private static void testIntegerEquals() {
 | 
				
			||||
        Integer a = new Integer(42);
 | 
				
			||||
        Integer b = new Integer(42);
 | 
				
			||||
        Integer c = null;
 | 
				
			||||
 | 
				
			||||
        if (!a.equals(b)) {
 | 
				
			||||
            c.intValue();
 | 
				
			||||
        }
 | 
				
			||||
 | 
				
			||||
        if (a != 42) {
 | 
				
			||||
            c.intValue();
 | 
				
			||||
        }
 | 
				
			||||
    }
 | 
				
			||||
 | 
				
			||||
}
 | 
				
			||||
@ -0,0 +1,44 @@
 | 
				
			||||
// Copyright (c) 2015-Present Facebook. All rights reserved.
 | 
				
			||||
 | 
				
			||||
package endtoend.java.infer;
 | 
				
			||||
 | 
				
			||||
import static org.hamcrest.MatcherAssert.assertThat;
 | 
				
			||||
import static utils.matchers.ResultContainsNoErrorInMethod.doesNotContain;
 | 
				
			||||
 | 
				
			||||
import org.junit.BeforeClass;
 | 
				
			||||
import org.junit.Test;
 | 
				
			||||
 | 
				
			||||
import java.io.IOException;
 | 
				
			||||
 | 
				
			||||
import utils.InferException;
 | 
				
			||||
import utils.InferResults;
 | 
				
			||||
 | 
				
			||||
public class IntegerClassTest {
 | 
				
			||||
 | 
				
			||||
  public static final String SOURCE_FILE =
 | 
				
			||||
      "infer/tests/codetoanalyze/java/infer/IntegerExample.java";
 | 
				
			||||
 | 
				
			||||
  public static final String NULL_DEREFERENCE = "NULL_DEREFERENCE";
 | 
				
			||||
 | 
				
			||||
  private static InferResults inferResults;
 | 
				
			||||
 | 
				
			||||
  @BeforeClass
 | 
				
			||||
  public static void loadResults() throws IOException {
 | 
				
			||||
    inferResults = InferResults.loadInferResults(IntegerClassTest.class, SOURCE_FILE);
 | 
				
			||||
  }
 | 
				
			||||
 | 
				
			||||
  @Test
 | 
				
			||||
  public void test()
 | 
				
			||||
      throws InterruptedException, IOException, InferException {
 | 
				
			||||
    assertThat(
 | 
				
			||||
        "Results should not contain NPE errors",
 | 
				
			||||
        inferResults,
 | 
				
			||||
        doesNotContain(
 | 
				
			||||
            NULL_DEREFERENCE,
 | 
				
			||||
            SOURCE_FILE,
 | 
				
			||||
            "testIntegerEquals"
 | 
				
			||||
        )
 | 
				
			||||
    );
 | 
				
			||||
  }
 | 
				
			||||
 | 
				
			||||
}
 | 
				
			||||
					Loading…
					
					
				
		Reference in new issue