Reviewed By: jvillard Differential Revision: D13180369 fbshipit-source-id: 5684ed318master
							parent
							
								
									f4e9975783
								
							
						
					
					
						commit
						2c6a705116
					
				| @ -1,91 +0,0 @@ | ||||
| /* | ||||
|  * Copyright (c) 2018-present, Facebook, Inc. | ||||
|  * | ||||
|  * This source code is licensed under the MIT license found in the | ||||
|  * LICENSE file in the root directory of this source tree. | ||||
|  */ | ||||
| 
 | ||||
| package codetoanalyze.java.checkers; | ||||
| 
 | ||||
| import com.facebook.infer.annotation.ThreadSafe; | ||||
| 
 | ||||
| class Interprocedural { | ||||
| 
 | ||||
|   static class A { | ||||
|     B f = new B(); | ||||
|     int h = 0; | ||||
|   } | ||||
| 
 | ||||
|   static class B { | ||||
|     int g = 0; | ||||
|   } | ||||
| 
 | ||||
|   @ThreadSafe | ||||
|   static class Field { | ||||
|     private A a = new A(); | ||||
| 
 | ||||
|     private void destabilize() { | ||||
|       B b = a.f; | ||||
|     } | ||||
| 
 | ||||
|     public void unstable_ok() { | ||||
|       int x = 42; | ||||
|       destabilize(); | ||||
|       synchronized (this) { | ||||
|         a.f.g = 101; | ||||
|       } | ||||
|       x = a.f.g; | ||||
|     } | ||||
| 
 | ||||
|     public void stable_bad() { | ||||
|       int x = 42; | ||||
|       synchronized (this) { | ||||
|         a.f.g = 101; | ||||
|       } | ||||
|       x = a.f.g; | ||||
|     } | ||||
|   } | ||||
| 
 | ||||
|   @ThreadSafe | ||||
|   static class Param { | ||||
| 
 | ||||
|     private void destabilize(A z) { | ||||
|       B b1 = z.f; | ||||
|       System.out.println(b1); | ||||
|     } | ||||
| 
 | ||||
|     public void unstable_ok(A a) { | ||||
|       int x = 42; | ||||
|       destabilize(a); | ||||
|       synchronized (this) { | ||||
|         a.f.g = 101; | ||||
|       } | ||||
|       x = a.f.g; | ||||
|     } | ||||
| 
 | ||||
|     public void stable_bad(A a) { | ||||
|       int x = 42; | ||||
|       synchronized (this) { | ||||
|         a.f.g = 101; | ||||
|       } | ||||
|       x = a.f.g; | ||||
|     } | ||||
|   } | ||||
| 
 | ||||
|   @ThreadSafe | ||||
|   static class Param2 { | ||||
| 
 | ||||
|     private void destabilize(A z) { | ||||
|       // Do nothing
 | ||||
|     } | ||||
| 
 | ||||
|     public void stable_bad(A a) { | ||||
|       int x = 42; | ||||
|       destabilize(a); // a leaks, but shouldn't be de-stabilized because callee does nothing
 | ||||
|       synchronized (this) { | ||||
|         a.f.g = 101; | ||||
|       } | ||||
|       x = a.f.g; | ||||
|     } | ||||
|   } | ||||
| } | ||||
| @ -1,86 +0,0 @@ | ||||
| /* | ||||
|  * Copyright (c) 2018-present, Facebook, Inc. | ||||
|  * | ||||
|  * This source code is licensed under the MIT license found in the | ||||
|  * LICENSE file in the root directory of this source tree. | ||||
|  */ | ||||
| 
 | ||||
| package codetoanalyze.java.checkers; | ||||
| 
 | ||||
| import com.facebook.infer.annotation.ThreadSafe; | ||||
| 
 | ||||
| class Intraprocedural { | ||||
| 
 | ||||
|   static class B { | ||||
|     int g = 0; | ||||
|   } | ||||
| 
 | ||||
|   static class A { | ||||
|     B f = new B(); | ||||
|     int h = 0; | ||||
|   } | ||||
| 
 | ||||
|   @ThreadSafe | ||||
|   static class Field { | ||||
|     private A a = new A(); | ||||
| 
 | ||||
|     public void unstable_ok() { | ||||
|       int x = 42; | ||||
|       B b = a.f; // destabilizes
 | ||||
|       synchronized (this) { | ||||
|         a.f.g = 101; | ||||
|       } | ||||
|       x = a.f.g; | ||||
|     } | ||||
| 
 | ||||
|     public void FN_stable_bad() { | ||||
|       int x = 42; | ||||
|       synchronized (this) { | ||||
|         a.f.g = 101; | ||||
|       } | ||||
|       x = a.f.g; | ||||
|     } | ||||
|   } | ||||
| 
 | ||||
|   static class Param { | ||||
| 
 | ||||
|     public void unstable_ok(A a) { | ||||
|       int x = 42; | ||||
|       B b = a.f; // destabilizes
 | ||||
|       synchronized (this) { | ||||
|         a.f.g = 101; | ||||
|       } | ||||
|       x = a.f.g; | ||||
|     } | ||||
| 
 | ||||
|     public void stable_bad(A a) { | ||||
|       int x = 42; | ||||
|       synchronized (this) { | ||||
|         a.f.g = 101; | ||||
|       } | ||||
|       x = a.f.g; | ||||
|     } | ||||
|   } | ||||
| 
 | ||||
|   @ThreadSafe | ||||
|   static class Global { | ||||
|     private static A a = new A(); | ||||
| 
 | ||||
|     public synchronized A getA() { | ||||
|       return a; | ||||
|     } | ||||
| 
 | ||||
|     public synchronized void setA(A newA) { | ||||
|       a = newA; | ||||
|     } | ||||
| 
 | ||||
|     public void unstable_ok() { | ||||
|       int x = 42; | ||||
|       A a = getA(); // destabilizes
 | ||||
|       synchronized (this) { | ||||
|         a.f.g = 101; | ||||
|       } | ||||
|       x = a.f.g; | ||||
|     } | ||||
|   } | ||||
| } | ||||
| @ -1,12 +0,0 @@ | ||||
| # Copyright (c) 2016-present, Facebook, Inc.
 | ||||
| #
 | ||||
| # This source code is licensed under the MIT license found in the
 | ||||
| # LICENSE file in the root directory of this source tree.
 | ||||
| 
 | ||||
| TESTS_DIR = ../../.. | ||||
| 
 | ||||
| INFER_OPTIONS = --racerd-only --debug-exceptions --racerd-use-path-stability | ||||
| INFERPRINT_OPTIONS = --issues-tests | ||||
| SOURCES = $(wildcard *.java) | ||||
| 
 | ||||
| include $(TESTS_DIR)/javac.make | ||||
| @ -1,3 +0,0 @@ | ||||
| codetoanalyze/java/stability/Interprocedural.java, codetoanalyze.java.checkers.Interprocedural$Param.stable_bad(codetoanalyze.java.checkers.Interprocedural$A):void, 71, THREAD_SAFETY_VIOLATION, no_bucket, ERROR, [<Read trace>,access to `a.codetoanalyze.java.checkers.Interprocedural$A.f.codetoanalyze.java.checkers.Interprocedural$B.g`,<Write trace>,access to `a.codetoanalyze.java.checkers.Interprocedural$A.f.codetoanalyze.java.checkers.Interprocedural$B.g`] | ||||
| codetoanalyze/java/stability/Interprocedural.java, codetoanalyze.java.checkers.Interprocedural$Param2.stable_bad(codetoanalyze.java.checkers.Interprocedural$A):void, 88, THREAD_SAFETY_VIOLATION, no_bucket, ERROR, [<Read trace>,access to `a.codetoanalyze.java.checkers.Interprocedural$A.f.codetoanalyze.java.checkers.Interprocedural$B.g`,<Write trace>,access to `a.codetoanalyze.java.checkers.Interprocedural$A.f.codetoanalyze.java.checkers.Interprocedural$B.g`] | ||||
| codetoanalyze/java/stability/Intraprocedural.java, codetoanalyze.java.checkers.Intraprocedural$Param.stable_bad(codetoanalyze.java.checkers.Intraprocedural$A):void, 61, THREAD_SAFETY_VIOLATION, no_bucket, ERROR, [<Read trace>,access to `a.codetoanalyze.java.checkers.Intraprocedural$A.f.codetoanalyze.java.checkers.Intraprocedural$B.g`,<Write trace>,access to `a.codetoanalyze.java.checkers.Intraprocedural$A.f.codetoanalyze.java.checkers.Intraprocedural$B.g`] | ||||
					Loading…
					
					
				
		Reference in new issue