Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-66445

Prevent bad warning log if new "additional-stop-words.txt" does not exist

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: In Review (View Workflow)
    • Priority: Minor
    • Resolution: Unresolved
    • Component/s: support-core-plugin
    • Labels:
      None
    • Environment:
      support core plugin v2.75
    • Similar Issues:

      Description

      See JENKINS-66023 and https://github.com/jenkinsci/support-core-plugin/pull/298/files#diff-5a8ed81f72c628f3870f2fc2f9a0946cd6356e25cc62a71dde4e4f58be8a6607R170

      2021-08-24 12:32:01.831+0000 [id=84]	WARNING	c.c.j.s.filter.ContentMappings#getAdditionalStopWords: Could not load user provided stop words as /var/jenkins_home/support/additional-stop-words.txt does not exist or is not readable.
      

      This popped up in a paranoid self-testing pipeline after building and starting a Jenkins Docker image and then checking all logs for very defensively: any unexpected warning logs fail the self-test pipeline.

      I think this new "additional-stop-words.txt" file must not exist and so it should not log a warning?

        Attachments

          Issue Links

            Activity

            Hide
            reinholdfuereder Reinhold Füreder added a comment -

            Maybe the following (untested) code could be an appropriate improvement/fix?

            File f = new File(fileLocation);
            if (f.exists()) {
              if (!f.canRead()) {
                LOGGER.log(Level.WARNING, "Could not load user provided stop words as " + fileLocation + " is not readable.");
              } else {
                try (BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(fileLocation), Charset.defaultCharset()))) {
                  for (String line = br.readLine(); line != null; line = br.readLine()) {
                    if (StringUtils.isNotEmpty(line)) {
                      words.add(line);
                    }
                  }
                  return words;
                } catch (IOException ex) {
                  LOGGER.log(Level.WARNING, "Could not load user provided stop words " + fileLocation 
                      + " due to unexpected i/o error.", ex);
                }
              }
            }
            

            Please also mind the change in the second log output.

            Show
            reinholdfuereder Reinhold Füreder added a comment - Maybe the following (untested) code could be an appropriate improvement/fix? File f = new File(fileLocation); if (f.exists()) { if (!f.canRead()) { LOGGER.log(Level.WARNING, "Could not load user provided stop words as " + fileLocation + " is not readable." ); } else { try (BufferedReader br = new BufferedReader( new InputStreamReader( new FileInputStream(fileLocation), Charset.defaultCharset()))) { for ( String line = br.readLine(); line != null ; line = br.readLine()) { if (StringUtils.isNotEmpty(line)) { words.add(line); } } return words; } catch (IOException ex) { LOGGER.log(Level.WARNING, "Could not load user provided stop words " + fileLocation + " due to unexpected i/o error." , ex); } } } Please also mind the change in the second log output.
            Hide
            reinholdfuereder Reinhold Füreder added a comment -

            Maybe Allan BURDAJEWICZ is the more appropriate assignee for this little issue?

            Show
            reinholdfuereder Reinhold Füreder added a comment - Maybe Allan BURDAJEWICZ is the more appropriate assignee for this little issue?
            Hide
            reinholdfuereder Reinhold Füreder added a comment -

            As I was just updating our Jenkins instances from 2.303.1 to 2.303.2 I stumbled over this issue again:

            • Any news/updates?
            • I had naively hoped this is a rather low hanging fruit?

            Many thanks in advance...

            Show
            reinholdfuereder Reinhold Füreder added a comment - As I was just updating our Jenkins instances from 2.303.1 to 2.303.2 I stumbled over this issue again: Any news/updates? I had naively hoped this is a rather low hanging fruit? Many thanks in advance...
            Hide
            allan_burdajewicz Allan BURDAJEWICZ added a comment -

            Sorry for the delay. Will look into this shortly. The proposed fix looks good. I think we should log a WARNING only if the file location is provided with a system property, but that provided location does not exists.

            Show
            allan_burdajewicz Allan BURDAJEWICZ added a comment - Sorry for the delay. Will look into this shortly. The proposed fix looks good. I think we should log a WARNING only if the file location is provided with a system property, but that provided location does not exists.
            Hide
            reinholdfuereder Reinhold Füreder added a comment -

            Thanks Allan BURDAJEWICZ: sounds good! Looking forward to the fix...

            Show
            reinholdfuereder Reinhold Füreder added a comment - Thanks Allan BURDAJEWICZ : sounds good! Looking forward to the fix...

              People

              Assignee:
              allan_burdajewicz Allan BURDAJEWICZ
              Reporter:
              reinholdfuereder Reinhold Füreder
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Dates

                Created:
                Updated: