-
-
Notifications
You must be signed in to change notification settings - Fork 754
Open
Description
Describe the bug
The IOUtils.close function:
atmosphere/modules/cpr/src/main/java/org/atmosphere/util/IOUtils.java
Lines 463 to 486 in d350bc5
| /** | |
| * <p> | |
| * Tries to close the given objects and log the {@link IOException} at INFO level | |
| * to make the code more readable when we assume that the {@link IOException} won't be managed. | |
| * </p> | |
| * <p/> | |
| * <p> | |
| * Also ignore {@code null} parameters. | |
| * </p> | |
| * | |
| * @param closeableArray the objects to close | |
| */ | |
| public static void close(final Closeable... closeableArray) { | |
| for (Closeable closeable : closeableArray) { | |
| try { | |
| if (closeable != null) { | |
| closeable.close(); | |
| } | |
| } catch (IOException ioe) { | |
| logger.info("Can't close the object", ioe); | |
| } | |
| } | |
| } | |
throws a null pointer exception if it is called with one single parameter which is null.
Atmosphere Info
- version: all since b31804c
- atmosphere.js version NA
- extensions used None
Expected behavior
Should not throw null.
Screenshots
Systems (please complete the following information):
- OS: NA
- Browser name and version: NA
- Java version and distribution: at least Java 21 probably more
- Serveur name and version: NA
Additional context
This is an edge case of Java behavior of varargs.
An improved implementation could be:
if (closeableArray != null) {
for (Closeable closeable : closeableArray) {
if (closeable != null) {
try {
closeable.close();
} catch (IOException ioe) {
logger.info("Can't close the object", ioe);
}
}
}
}
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels