Skip to content

Conversation

jglick
Copy link
Member

@jglick jglick commented Apr 24, 2025

Noticed in a support bundle several exceptions of the form

WARNING	c.c.j.s.a.UnfilteredFileContent#lambda$createBaseFileContent$0: Error opening file /var/jenkins_home/slow-requests/20250424-134904.013.txt
java.io.FileNotFoundException: /var/jenkins_home/slow-requests/20250424-134904.013.txt (No such file or directory)
	at java.base/java.io.FileInputStream.open0(Native Method)
	at java.base/java.io.FileInputStream.open(FileInputStream.java:213)
	at java.base/java.io.FileInputStream.<init>(FileInputStream.java:152)
	at PluginClassLoader for support-core//com.cloudbees.jenkins.support.api.UnfilteredFileContent.getInputStream(UnfilteredFileContent.java:85)
	at PluginClassLoader for support-core//com.cloudbees.jenkins.support.api.UnfilteredFileContent.lambda$createBaseFileContent$0(UnfilteredFileContent.java:91)
	at PluginClassLoader for support-core//com.cloudbees.jenkins.support.api.BaseFileContent.writeTo(BaseFileContent.java:102)
	at PluginClassLoader for support-core//com.cloudbees.jenkins.support.api.UnfilteredFileContent.writeTo(UnfilteredFileContent.java:71)
	at PluginClassLoader for support-core//com.cloudbees.jenkins.support.SupportPlugin.writeBundle(SupportPlugin.java:491)
	at PluginClassLoader for support-core//com.cloudbees.jenkins.support.SupportPlugin.writeBundle(SupportPlugin.java:355)
	at PluginClassLoader for support-core//com.cloudbees.jenkins.support.SupportPlugin$PeriodicWorkImpl.lambda$doRun$0(SupportPlugin.java:1077)
	at java.base/java.lang.Thread.run(Thread.java:1583)
WARNING	c.c.j.support.SupportPlugin#writeBundle: Could not attach ''slow-requests/20250424-134904.013.txt'' to support bundle
java.lang.NullPointerException: Cannot invoke "java.io.InputStream.read(byte[], int, int)" because "this.in" is null
	at java.base/java.io.FilterInputStream.read(FilterInputStream.java:119)
	at PluginClassLoader for support-core//com.cloudbees.jenkins.support.api.BaseFileContent$TruncatedInputStream.read(BaseFileContent.java:227)
	at java.base/java.io.FilterInputStream.read(FilterInputStream.java:95)
	at org.apache.commons.io.IOUtils.copyLarge(IOUtils.java:1486)
	at org.apache.commons.io.IOUtils.copy(IOUtils.java:1111)
	at org.apache.commons.io.IOUtils.copyLarge(IOUtils.java:1459)
	at org.apache.commons.io.IOUtils.copy(IOUtils.java:1089)
	at PluginClassLoader for support-core//com.cloudbees.jenkins.support.api.BaseFileContent.writeTo(BaseFileContent.java:106)
	at PluginClassLoader for support-core//com.cloudbees.jenkins.support.api.UnfilteredFileContent.writeTo(UnfilteredFileContent.java:71)
	at PluginClassLoader for support-core//com.cloudbees.jenkins.support.SupportPlugin.writeBundle(SupportPlugin.java:491)
	at PluginClassLoader for support-core//com.cloudbees.jenkins.support.SupportPlugin.writeBundle(SupportPlugin.java:355)
	at PluginClassLoader for support-core//com.cloudbees.jenkins.support.SupportPlugin$PeriodicWorkImpl.lambda$doRun$0(SupportPlugin.java:1077)
	at java.base/java.lang.Thread.run(Thread.java:1583)

This seems to be due to a Supplier<InputStream> returning null, which was not expected by the caller. #190 fixed this for FileContent but not UnfilteredFileContent.

@jglick jglick requested a review from a team as a code owner April 24, 2025 17:37
@jglick jglick added the bug label Apr 24, 2025
IOUtils.copy(new TruncatedInputStream(is, maxSize), os);
}
void writeTo(OutputStream os) throws IOException {
try (InputStream is = inputStreamSupplier.get()) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(ignore ws)

Comment on lines -132 to +114
try {
try (InputStream is = inputStreamSupplier.get()) {
if (maxSize == -1) {
try (BufferedReader reader = new BufferedReader(new InputStreamReader(is, ENCODING))) {
String s;
while ((s = reader.readLine()) != null) {
String filtered = ContentFilter.filter(filter, secretsFilterFunction.apply(s)) + "\n";
IOUtils.write(filtered, os, ENCODING);
}
try (InputStream is = inputStreamSupplier.get()) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Double try block seems unnecessary. Dates to #206.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct, could just be included down in the trys in each conditions.

return getInputStream();
} catch (IOException e) {
LOGGER.log(Level.WARNING, "Error opening file " + file, e);
return null;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug dates to #174.


/**
* Utility class with the common logic to FileContent and UnfilteredFileContent.
*
* @author Stephen Connolly, M Ramón León
*/
@Restricted(NoExternalUse.class)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was this ever restricted in #174? It was never public.

@@ -67,27 +69,9 @@ class BaseFileContent {

private static final String ENCODING = "UTF-8";

/**
* @deprecated (as it is placed in the api package we keep backward compatibility, no relevant usage was found)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was this left in place in c6d20da? The class was not exposed outside the package.


@FunctionalInterface
interface InputStreamSupplier {
InputStream get() throws IOException;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Letting the caller handle the IOException. #174 appears to have been catching FileNotFoundException for this reason, but that could not actually have been thrown from the body of the try block: other IOExceptions from handling OutputStream, perhaps, but the Supplier permitted no IOException so FileNotFoundException was being caught earlier.

Copy link
Contributor

@Dohbedoh Dohbedoh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Jesse. I think this is https://issues.jenkins.io/browse/JENKINS-64261.
Overall looks good to me.

@Dohbedoh Dohbedoh changed the title BaseFileContent.InputStreamSupplier [JENKINS-64261] BaseFileContent.InputStreamSupplier Apr 25, 2025
@jglick jglick merged commit 63c3a2f into jenkinsci:master Apr 25, 2025
17 checks passed
@jglick jglick deleted the InputStreamSupplier branch April 25, 2025 14:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants