Commit 7c6b17c
Make
This generally makes it more resilient and future-proof, but we still don't recommend relying on GC for object cleanup, in part because any small change (like this one) could upset a delicate balance somewhere.
Also, while I'm messing with `reachabilityFence` again: Remove a confused comment from 7eba58f in `GcFinalizationTest`: Once we use `reachabilityFence` directly, we'll eliminate the helper method, and http://errorprone.info/bugpattern/ReachabilityFenceUsage will remain happy because the call to `reachabilityFence` will appear directly inside a `finally` block. (I'm still not sure that `finally` is necessary there, but it's easy, and it's probably reasonable as a default practice.)
(I'm also not sure if `finally` is necessary for the new usages of `reachabilityFence` in `FileBackedOutputStream`. I guess the fear would be that we'd allow the `FileOutputStream` to be closed while it's in the process of preparing to throw an exception, and the `close` call could clear something that the exception-construction code wants to read? I do suspect that the new `reachabilityFence` calls are a good idea to have _somewhere_, whether in a `finally` block or not, to ensure that background cleanup doesn't `reset` a `FileBackedOutputStream` during a call to a method like `write` (which might then open a _new_ file) or `close` (which might then not see an exception because the background `reset` sees it instead). Or maybe [`reachabilityFence` isn't necessary because our methods are `synchronized`](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/ref/Reference.html#reachabilityFence(java.lang.Object)). (`synchronized` should at least mean that we don't need the fence in a `finally` block, at least not for the reasons that I mentioned above: It won't be possible to `reset` the stream until `write` or `close` exits the critical area.) But presumably it won't hurt anything.)
RELNOTES=n/a
PiperOrigin-RevId: 875720195FileBackedOutputStream use PhantomReference instead of finalize().1 parent 166a675 commit 7c6b17c
12 files changed
Lines changed: 604 additions & 448 deletions
File tree
- android
- guava-testlib
- src/com/google/common/testing
- test/com/google/common/testing
- guava-tests/test/com/google/common/io
- guava/src/com/google/common
- io
- util/concurrent
- guava-testlib
- src/com/google/common/testing
- test/com/google/common/testing
- guava-tests/test/com/google/common/io
- guava/src/com/google/common
- io
- util/concurrent
Lines changed: 5 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
138 | 138 | | |
139 | 139 | | |
140 | 140 | | |
141 | | - | |
| 141 | + | |
142 | 142 | | |
143 | 143 | | |
144 | 144 | | |
| |||
171 | 171 | | |
172 | 172 | | |
173 | 173 | | |
174 | | - | |
| 174 | + | |
175 | 175 | | |
176 | 176 | | |
177 | 177 | | |
| |||
200 | 200 | | |
201 | 201 | | |
202 | 202 | | |
203 | | - | |
| 203 | + | |
204 | 204 | | |
205 | 205 | | |
206 | 206 | | |
| |||
232 | 232 | | |
233 | 233 | | |
234 | 234 | | |
235 | | - | |
| 235 | + | |
236 | 236 | | |
237 | 237 | | |
238 | 238 | | |
| |||
298 | 298 | | |
299 | 299 | | |
300 | 300 | | |
301 | | - | |
| 301 | + | |
302 | 302 | | |
303 | 303 | | |
304 | 304 | | |
| |||
Lines changed: 34 additions & 41 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
19 | | - | |
20 | 19 | | |
21 | 20 | | |
22 | 21 | | |
23 | | - | |
24 | 22 | | |
25 | 23 | | |
26 | 24 | | |
27 | 25 | | |
| 26 | + | |
28 | 27 | | |
29 | 28 | | |
30 | 29 | | |
| |||
51 | 50 | | |
52 | 51 | | |
53 | 52 | | |
54 | | - | |
| 53 | + | |
55 | 54 | | |
56 | 55 | | |
57 | 56 | | |
| |||
66 | 65 | | |
67 | 66 | | |
68 | 67 | | |
69 | | - | |
| 68 | + | |
70 | 69 | | |
71 | 70 | | |
72 | 71 | | |
| |||
82 | 81 | | |
83 | 82 | | |
84 | 83 | | |
85 | | - | |
| 84 | + | |
86 | 85 | | |
87 | 86 | | |
88 | 87 | | |
| |||
103 | 102 | | |
104 | 103 | | |
105 | 104 | | |
106 | | - | |
107 | | - | |
108 | | - | |
109 | | - | |
110 | | - | |
111 | | - | |
112 | | - | |
| 105 | + | |
113 | 106 | | |
114 | 107 | | |
115 | 108 | | |
| |||
202 | 195 | | |
203 | 196 | | |
204 | 197 | | |
205 | | - | |
206 | | - | |
207 | | - | |
208 | | - | |
209 | | - | |
210 | | - | |
211 | | - | |
212 | | - | |
213 | | - | |
214 | | - | |
| 198 | + | |
215 | 199 | | |
216 | 200 | | |
217 | 201 | | |
| |||
227 | 211 | | |
228 | 212 | | |
229 | 213 | | |
230 | | - | |
| 214 | + | |
231 | 215 | | |
232 | | - | |
| 216 | + | |
233 | 217 | | |
234 | 218 | | |
235 | 219 | | |
| |||
247 | 231 | | |
248 | 232 | | |
249 | 233 | | |
250 | | - | |
251 | | - | |
252 | | - | |
253 | | - | |
254 | | - | |
255 | | - | |
256 | | - | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
257 | 251 | | |
258 | | - | |
259 | | - | |
260 | | - | |
261 | | - | |
262 | | - | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
263 | 256 | | |
264 | | - | |
265 | | - | |
| 257 | + | |
| 258 | + | |
266 | 259 | | |
267 | | - | |
268 | | - | |
269 | | - | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
270 | 263 | | |
271 | 264 | | |
272 | 265 | | |
Lines changed: 0 additions & 56 deletions
This file was deleted.
Lines changed: 24 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
| 20 | + | |
20 | 21 | | |
| 22 | + | |
| 23 | + | |
21 | 24 | | |
22 | 25 | | |
23 | 26 | | |
| |||
27 | 30 | | |
28 | 31 | | |
29 | 32 | | |
| 33 | + | |
30 | 34 | | |
31 | 35 | | |
32 | 36 | | |
| |||
54 | 58 | | |
55 | 59 | | |
56 | 60 | | |
57 | | - | |
| 61 | + | |
58 | 62 | | |
59 | 63 | | |
60 | | - | |
| 64 | + | |
| 65 | + | |
61 | 66 | | |
62 | 67 | | |
63 | 68 | | |
| |||
97 | 102 | | |
98 | 103 | | |
99 | 104 | | |
100 | | - | |
| 105 | + | |
101 | 106 | | |
102 | 107 | | |
103 | 108 | | |
| |||
197 | 202 | | |
198 | 203 | | |
199 | 204 | | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
200 | 221 | | |
0 commit comments