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
[JENKINS-58393] Catch exception thrown by getTime() #178
Conversation
If we just add the
What I am proposing here is to log a warning that we could not set the time properly and try to print that content anyway. |
@@ -79,7 +79,7 @@ public void writeTo(OutputStream os, ContentFilter filter) throws IOException { | |||
} | |||
|
|||
@Override | |||
public long getTime() throws IOException { | |||
public long getTime() { |
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.
The fix looks good, but is this a realistic scenario? I mean when do you expect an exception being thrown when retrieving the time?
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.
FileContent#getTime
is never thrown. Which is why I removed it. FilePathContent#getTime() is what can throw an exception (reading the time through a remote channel).
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.
Better to move entry.setTime(content.getTime())
into the try {
on the next line
@@ -312,7 +312,19 @@ public static void writeBundle(OutputStream outputStream, final List<Component> | |||
} | |||
final String name = getNameFiltered(maybeFilter, content.getName(), content.getFilterableParameters()); | |||
final ZipArchiveEntry entry = new ZipArchiveEntry(name); | |||
entry.setTime(content.getTime()); | |||
|
|||
try { |
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.
It happens only with contents based on Files and it's due to a lack of permissions if I understood correctly. For me, it's better to just move the instruction into the existing try {
that avoids breaking the loop if something wrong happens with a specific content.
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.
@MRamonLeon if an exception is raised before doing binaryOut.putArchiveEntry(entry)
, the method binaryOut.closeArchiveEntry()
will fail:
try {
// if an exception is raised here
binaryOut.putArchiveEntry(entry);
[...]
} catch (Throwable e) {
[...]
} finally {
[...]
binaryOut.closeArchiveEntry(); // This breaks with `java.io.IOException: No current entry to close`
}
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.
If the exception is raised inside the method (which is possible) it's going to fail as well. I suppose bynaryOut.closeArchiveEntry();
should go at the end of the try
section, but then the two previous sentences should go there too. The logic about these streams is very messy and deserves a bit of clean up. My concern is that if we cannot get the time of the entry, we are not going to be able to get the full content of that. Therefore, my proposal to include it all together in the same try
. I've seen some implementation enclosing the closeArchiveEntry in a try-catch clause, but it's almost the same. So I leave it up to you.
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.
My concern is that if we cannot get the time of the entry, we are not going to be able to get the full content of that.
You are right. I think in most cases, if we cannot get the time we cannot get the content.
Even the two previous instructions could be moved too |
Co-Authored-By: Ramon Leon <manuelramonleonjimenez@gmail.com>
4be3e7b
to
0a7146e
Compare
Looking into this, the |
@MRamonLeon I am still a bit dubious about the streams reset. Maybe these 2 reset should always be done before the |
@Dohbedoh we have to keep the
All the logic related to the Streams is a bit messy FMPOV. I would suggest doing some tests moving the
My understanding is that the first option should work. |
fba6d3e
to
49880de
Compare
I am good with this. I added a flag and conditionals.
I have done some tests, seemed to work. But I also not have been able to reproduce that IOE consistently. I feel like adding a flag is safer for now. |
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.
Great!
JENKINS-58393: An exception may be thrown when doing a
getTime()
but is not caught in the loop on contents.