You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@poi.apache.org by bu...@apache.org on 2023/04/28 08:59:59 UTC
[Bug 66584] New: ZipPackage can fail to handle excepions.
https://bz.apache.org/bugzilla/show_bug.cgi?id=66584
Bug ID: 66584
Summary: ZipPackage can fail to handle excepions.
Product: POI
Version: unspecified
Hardware: PC
Status: NEW
Severity: normal
Priority: P2
Component: POI Overall
Assignee: dev@poi.apache.org
Reporter: zhonghao@pku.org.cn
Target Milestone: ---
ZipPackage has a constructor:
ZipPackage(InputStream in, PackageAccess access) throws IOException {
super(access);
ZipArchiveThresholdInputStream zis = ZipHelper.openZipStream(in); //
NOSONAR
try {
this.zipArchive = new ZipInputStreamZipEntrySource(zis);
} catch (final IOException | RuntimeException e) {
IOUtils.closeQuietly(zis);
throw e;
}
}
Here, ZipHelper.openZipStream(in) can throw IOException, but it is not inside
the try statement. It can be put inside the try statement to avoid exceptions.
BTW, I notice that in the same class, IOException is caught and
InvalidOperationException is rethrown:
private static ZipEntrySource openZipEntrySourceStream(FileInputStream fis)
throws InvalidOperationException {
try {
// open the zip input stream
zis = ZipHelper.openZipStream(fis); // NOSONAR
} catch (final IOException e) {
// If the source cannot be acquired, abort (no resources to free at
this level)
throw new InvalidOperationException("Could not open the file input
stream", e);
}
...
}
--
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org
[Bug 66584] ZipPackage can fail to handle excepions.
Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=66584
PJ Fanning <fa...@yahoo.com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |RESOLVED
OS| |All
Resolution|--- |FIXED
--- Comment #1 from PJ Fanning <fa...@yahoo.com> ---
thanks - I made a change with r1909467
--
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org
[Bug 66584] ZipPackage can fail to handle excepions.
Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=66584
Dominik Stadler <do...@gmx.at> changed:
What |Removed |Added
----------------------------------------------------------------------------
Blocks| |67579
Referenced Bugs:
https://bz.apache.org/bugzilla/show_bug.cgi?id=67579
[Bug 67579] POI 5.2.4 is closing the input stream used in the XSSFWorkbook
constructor which explicitly specifies closeStream=false
--
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org
[Bug 66584] ZipPackage can fail to handle excepions.
Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=66584
--- Comment #2 from PJ Fanning <fa...@yahoo.com> ---
This change has been largely reverted as part of
https://bz.apache.org/bugzilla/show_bug.cgi?id=67579
The original change is in POI 5.2.4 but it is causing a regression will be
undone in future releases.
It is the responsibility of users who have InputStreams that they feed into POI
APIs to close those streams themselves.
Something like:
try(
InputStream stream = ...;
XSSFWorkbook workbook = new XSSFWorkbook(stream)
) {
// use workbook
}
The try-with-resources syntax will ensure that stream and workbook are closed
after the try block completes (regardless of whether there is an exception or
not).
--
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org