-
Notifications
You must be signed in to change notification settings - Fork 745
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update
MustBeClosed
to handle IO decorators.
Tested: TAP for global presubmit queue [] PiperOrigin-RevId: 682534861
- Loading branch information
Showing
3 changed files
with
212 additions
and
232 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
core/src/main/java/com/google/errorprone/bugpatterns/CloseableDecoratorTypes.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
* Copyright 2024 The Error Prone Authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.google.errorprone.bugpatterns; | ||
|
||
import com.google.common.collect.ImmutableSetMultimap; | ||
import java.io.FilterInputStream; | ||
import java.io.FilterOutputStream; | ||
import java.io.InputStream; | ||
import java.io.InputStreamReader; | ||
import java.io.OutputStream; | ||
import java.io.OutputStreamWriter; | ||
import java.io.Reader; | ||
import java.io.Writer; | ||
|
||
/** | ||
* Common {@link AutoCloseable} decorator types that wrap around {@link AutoCloseable} resources, | ||
* which are always closed when the enclosing decorators are closed. | ||
* | ||
* <p>Each value in the map is the common supertype of some {@link AutoCloseable} decorator types, | ||
* with the key being the common {@link AutoCloseable} type that they decorate. The decorated type | ||
* is always assumed to be the first argument to the constructor of the decorator type. | ||
*/ | ||
public final class CloseableDecoratorTypes { | ||
public static final ImmutableSetMultimap<String, String> CLOSEABLE_DECORATOR_TYPES = | ||
ImmutableSetMultimap.<String, String>builder() | ||
.putAll( | ||
InputStream.class.getName(), | ||
FilterInputStream.class.getName(), // e.g., BufferedInputStream | ||
InputStreamReader.class.getName()) | ||
.putAll( | ||
OutputStream.class.getName(), | ||
FilterOutputStream.class.getName(), // e.g., BufferedOutputStream | ||
OutputStreamWriter.class.getName()) | ||
.put(Reader.class.getName(), Reader.class.getName()) // e.g., BufferedReader | ||
.put(Writer.class.getName(), Writer.class.getName()) // e.g., BufferedWriter | ||
.build(); | ||
|
||
private CloseableDecoratorTypes() {} | ||
} |
Oops, something went wrong.