01: ////////////////////////////////////////////////////////////////////////////////
02: // Test case file for checkstyle.
03: // Created: 2001
04: ////////////////////////////////////////////////////////////////////////////////
05: package com.puppycrawl.tools.checkstyle;
06:
07: /**
08: * Test case for detection of double checked locking
09: * @author lkuehne
10: **/
11: class InputDoubleCheckedLocking {
12: static Integer one = null;
13:
14: private static Integer getOneCorrect() {
15: synchronized (InputDoubleCheckedLocking.class) {
16: if (one == null) {
17: one = new Integer(1);
18: }
19: }
20: return one;
21: }
22:
23: private static Integer getOneDCL() {
24: if (one == null) {
25: System.out.println("just to make the AST interesting");
26: synchronized (InputDoubleCheckedLocking.class) {
27: if (one == null) {
28: one = new Integer(1);
29: }
30: }
31: }
32: return one;
33: }
34:
35: private static Integer getSimilarToDCL() {
36: // different tests
37: if (one == null) {
38: synchronized (InputDoubleCheckedLocking.class) {
39: if (one == Integer.valueOf(2)) {
40: one = new Integer(1);
41: }
42: }
43: }
44:
45: // no synchronization
46: if (one == null) {
47: if (one == null) {
48: one = new Integer(1);
49: }
50: }
51:
52: // no outer test
53: synchronized (InputDoubleCheckedLocking.class) {
54: if (one == null) {
55: one = new Integer(1);
56: }
57: }
58: return one;
59: }
60:
61: }
|