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

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

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Minor Minor
    • support-core-plugin
    • None
    • support core plugin v2.75
    • support-core:2.77

      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?

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

          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.

          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.

          Maybe allan_burdajewicz is the more appropriate assignee for this little issue?

          Reinhold Füreder added a comment - Maybe allan_burdajewicz is the more appropriate assignee for this little issue?

          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...

          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...

          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.

          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.

          Thanks allan_burdajewicz: sounds good! Looking forward to the fix...

          Reinhold Füreder added a comment - Thanks allan_burdajewicz : sounds good! Looking forward to the fix...

          Release just done, should be out soon.

          Allan BURDAJEWICZ added a comment - Release just done, should be out soon.

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

              Created:
              Updated:
              Resolved: