-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
NPE when handling corrupt jar files #43
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -207,17 +207,25 @@ public Artifact getRecord() { | |
*/ | ||
protected Content getNextFile() throws IOException { | ||
JarEntry entry; | ||
if ((entry = jis.getNextJarEntry()) != null) { | ||
ByteArrayOutputStream bos = new ByteArrayOutputStream(); | ||
byte[] data = new byte[BUFFER]; | ||
int size; | ||
while ((size = jis.read(data, 0, data.length)) != -1) { | ||
bos.write(data, 0, size); | ||
} | ||
Content file = new Content(entry.getName(), bos.toByteArray()); | ||
bos.close(); | ||
return file; | ||
} | ||
ByteArrayOutputStream bos = new ByteArrayOutputStream(); | ||
try { | ||
if ((entry = jis.getNextJarEntry()) != null) { | ||
|
||
byte[] data = new byte[BUFFER]; | ||
int size; | ||
while ((size = jis.read(data, 0, data.length)) != -1) { | ||
bos.write(data, 0, size); | ||
} | ||
Content file = new Content(entry.getName(), bos.toByteArray()); | ||
bos.close(); | ||
return file; | ||
} | ||
} | ||
catch (IOException io) { | ||
io.printStackTrace(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Stacktrace should only be print if we are in debug mode etc. The message here should be more a user-friendly error. Additionally, note that the exception must be re-thrown in order for it to be handled by caller and a 'VictimsException' be thrown correctly up the call stack. |
||
bos.close(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use a ByteArrayOutputStream bos = new ByteArrayOutputStream();
Content file = null;
try {
// stuff
} catch (IOException io) {
// handle message handling and re-throw
} finally {
bos.close();
return file;
} |
||
System.out.println(new String(bos.toByteArray())); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why are we doing this? |
||
} | ||
return null; | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we handle all IOExceptions here or just NPEs?