diff --git a/infer/src/checkers/purityModels.ml b/infer/src/checkers/purityModels.ml index 9be81c7c1..0ed87c987 100644 --- a/infer/src/checkers/purityModels.ml +++ b/infer/src/checkers/purityModels.ml @@ -119,6 +119,7 @@ module ProcName = struct ; +PatternMatch.implements_lang "StringBuilder" &:: "" <>--> PurityDomain.pure ; +PatternMatch.implements_lang "StringBuilder" &:: "append" <>--> modifies_first ; +PatternMatch.implements_lang "StringBuilder" &:: "length" <>--> PurityDomain.pure + ; +PatternMatch.implements_lang "Object" &:: "clone" <>--> PurityDomain.pure ; +PatternMatch.implements_lang "Object" &:: "equals" <>--> PurityDomain.pure ; +PatternMatch.implements_lang "Object" &:: "toString" <>--> PurityDomain.pure ; +PatternMatch.implements_lang "Object" &:: "getClass" <>--> PurityDomain.pure diff --git a/infer/tests/codetoanalyze/java/purity/PurityModeled.java b/infer/tests/codetoanalyze/java/purity/PurityModeled.java index 8ea40adb2..ce402e104 100644 --- a/infer/tests/codetoanalyze/java/purity/PurityModeled.java +++ b/infer/tests/codetoanalyze/java/purity/PurityModeled.java @@ -4,6 +4,8 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */ +import java.util.ArrayList; + class PurityModeled { double math_random_impure() { @@ -15,4 +17,19 @@ class PurityModeled { // copies an array from the specified source array System.arraycopy(src, 0, dst, 0, 1); } + + enum Color { + RED, + GREEN, + BLUE; // values() calls clone + } + + public void enum_iter_pure() { + for (Color c : Color.values()) {} + } + + void clone_pure(ArrayList list) { + ArrayList cloned = (ArrayList) list.clone(); + cloned.add(""); // no change the list + } } diff --git a/infer/tests/codetoanalyze/java/purity/issues.exp b/infer/tests/codetoanalyze/java/purity/issues.exp index 46f2a12c1..f711748bd 100644 --- a/infer/tests/codetoanalyze/java/purity/issues.exp +++ b/infer/tests/codetoanalyze/java/purity/issues.exp @@ -4,7 +4,11 @@ codetoanalyze/java/purity/Localities.java, Localities.call_impure_with_fresh_arg codetoanalyze/java/purity/Localities.java, Localities.length_pure(java.util.ArrayList):int, 0, PURE_FUNCTION, no_bucket, ERROR, [Side-effect free function int Localities.length_pure(ArrayList)] codetoanalyze/java/purity/Localities.java, Localities.mkHC_pure(Localities$Counter):Localities$HasCounter, 0, PURE_FUNCTION, no_bucket, ERROR, [Side-effect free function Localities$HasCounter Localities.mkHC_pure(Localities$Counter)] codetoanalyze/java/purity/Localities.java, Localities.setFreshArrayEntry_pure(int,int):int[], 0, PURE_FUNCTION, no_bucket, ERROR, [Side-effect free function int[] Localities.setFreshArrayEntry_pure(int,int)] +codetoanalyze/java/purity/PurityModeled.java, PurityModeled$Color.valueOf(java.lang.String):PurityModeled$Color, 0, PURE_FUNCTION, no_bucket, ERROR, [Side-effect free function PurityModeled$Color PurityModeled$Color.valueOf(String)] +codetoanalyze/java/purity/PurityModeled.java, PurityModeled$Color.values():PurityModeled$Color[], 0, PURE_FUNCTION, no_bucket, ERROR, [Side-effect free function PurityModeled$Color[] PurityModeled$Color.values()] codetoanalyze/java/purity/PurityModeled.java, PurityModeled.arraycopy_pure(int[]):void, 0, PURE_FUNCTION, no_bucket, ERROR, [Side-effect free function void PurityModeled.arraycopy_pure(int[])] +codetoanalyze/java/purity/PurityModeled.java, PurityModeled.clone_pure(java.util.ArrayList):void, 0, PURE_FUNCTION, no_bucket, ERROR, [Side-effect free function void PurityModeled.clone_pure(ArrayList)] +codetoanalyze/java/purity/PurityModeled.java, PurityModeled.enum_iter_pure():void, 0, PURE_FUNCTION, no_bucket, ERROR, [Side-effect free function void PurityModeled.enum_iter_pure()] codetoanalyze/java/purity/Test.java, Test.call_pure_pure(int):void, 0, PURE_FUNCTION, no_bucket, ERROR, [Side-effect free function void Test.call_pure_pure(int)] codetoanalyze/java/purity/Test.java, Test.emptyList_impure_FP():java.util.ArrayList, 0, PURE_FUNCTION, no_bucket, ERROR, [Side-effect free function ArrayList Test.emptyList_impure_FP()] codetoanalyze/java/purity/Test.java, Test.local_alloc_pure(int,int):int, 0, PURE_FUNCTION, no_bucket, ERROR, [Side-effect free function int Test.local_alloc_pure(int,int)]