View Javadoc
1   package com.google.checkstyle.test.chapter6programpractice.rule64finalizers;
2   
3   class NormalFinalizer {
4   
5       public static void doStuff() {
6           // This method do some stuff
7       }
8   
9       protected void finalize() throws Throwable { //warn
10          try {
11              doStuff();
12          } finally {
13              super.finalize();
14          }
15      }
16  }
17  
18  // negates effect of superclass finalizer
19  class EmptyFinalizer {
20  
21      protected void finalize() throws Throwable { //warn
22          // empty finalize ()
23      }
24  }
25  
26  // fails to call superclass finalize method
27  class WithoutTryCatchFinalizer {
28  
29      public static void doStuff() {
30          // This method do some stuff
31      }
32  
33      protected void finalize() throws Throwable { //warn
34          doStuff();
35      }
36  }
37  
38  // public finalizer
39  class PublicFinalizer {
40  
41      public static void doStuff() {
42          // This method do some stuff
43      }
44  
45      public void finalize() throws Throwable { //warn
46          try {
47              doStuff();
48          } finally {
49              super.finalize();
50          }
51      }
52  }
53  
54  // unless (or worse) finalizer
55  class SuperFinalizer {
56  
57      protected void finalize() throws Throwable { //warn
58          super.finalize();
59      }
60  }
61  
62  // public finalizer
63  class StaticFinalizer {
64  
65      public static void doStuff() {
66          // This method do some stuff
67      }
68  
69      protected void finalize() { //warn
70          try {
71              doStuff();
72          } finally {
73  
74          }
75      }
76  
77      class InnerFinalizer {
78  
79          protected void finalize() { //warn
80              try {
81                  doStuff();
82              } finally {
83  
84              }
85          }
86      }
87  }
88  
89  class WithoutFinalize {
90      public void doStuff() {
91          // This method do some stuff
92      }
93  
94      public void finalizeMe() {
95          // This method do some stuff
96      }
97  
98      public void doFinalize() {
99          // This method do some stuff
100     }
101 }
102 
103 class WithoutMethods {}
104 
105 class WithAnonymousClass {
106     
107     public static void doStuff() {
108         // This method do some stuff
109     }
110     
111     public void foo() {
112         
113         Ball b = new Ball() {
114             
115             public void hit() {
116                 System.identityHashCode("You hit it!");
117             }
118 
119             protected void finalize() { //warn
120                 try {
121                     doStuff();
122                 } finally {
123 
124                 }
125             }
126         };
127         b.hit();
128     }
129 
130     interface Ball {
131         void hit();
132     }
133 }
134 
135 interface WithFinalizer {
136     void finalize(); //warn
137 }