• Icon: Improvement Improvement
    • Resolution: Fixed
    • Icon: Major Major
    • core
    • 2.324

      Inspired by JENKINS-17757. hudson.Util should have a convenience method to call a listener method (as a Runnable? for future lambdas) catching any RuntimeException or LinkageError and politely reporting the error so the caller (e.g. SlaveComputer.setChannel) can continue—maybe even blacklisting the listener for future calls so you do not fill up your log, listing the plugin name and version owning the listener class, etc.

          [JENKINS-21224] Catch all errors thrown by listeners

          Daniel Beck added a comment -

          Not catching exceptions in the listener call might be considered part of the API of some listeners. This is what enables my login rate limiter plugin

          Daniel Beck added a comment - Not catching exceptions in the listener call might be considered part of the API of some listeners. This is what enables my login rate limiter plugin

          Jesse Glick added a comment -

          That is definitely not a supported use case. A listener is for receiving event notifications only. APIs intended to allow listeners to affect the caller state so explicitly and generally have a different signature, either throwing a checked exception or returning boolean.

          Jesse Glick added a comment - That is definitely not a supported use case. A listener is for receiving event notifications only. APIs intended to allow listeners to affect the caller state so explicitly and generally have a different signature, either throwing a checked exception or returning boolean .

          Code changed in jenkins
          User: Jesse Glick
          Path:
          core/src/main/java/hudson/model/listeners/ItemListener.java
          http://jenkins-ci.org/commit/jenkins/6825121f06d6427304fd5149531216ecae6fdf93
          Log:
          JENKINS-21224 Defend against exceptions in listeners, for now just for ItemListener.
          java.lang.RuntimeException: Unable to copy /…/jobs/…/config.xml
          at hudson.plugins.jobConfigHistory.FileHistoryDao.createNewHistoryEntryAndCopyConfig(FileHistoryDao.java:252)
          at hudson.plugins.jobConfigHistory.FileHistoryDao.createNewItem(FileHistoryDao.java:238)
          at hudson.plugins.jobConfigHistory.JobConfigHistoryJobListener.onCreated(JobConfigHistoryJobListener.java:31)
          at hudson.model.listeners.ItemListener.fireOnCreated(ItemListener.java:161)
          at jenkins.model.Jenkins.putItem(Jenkins.java:2483)
          at …
          Caused by: java.io.FileNotFoundException: /…/jobs/…/config.xml (No such file or directory)
          at java.io.FileInputStream.open(Native Method)
          at java.io.FileInputStream.<init>(FileInputStream.java:120)
          at hudson.plugins.jobConfigHistory.FileHistoryDao.copyConfigFile(FileHistoryDao.java:178)
          at hudson.plugins.jobConfigHistory.FileHistoryDao.createNewHistoryEntryAndCopyConfig(FileHistoryDao.java:250)
          ... 108 more

          SCM/JIRA link daemon added a comment - Code changed in jenkins User: Jesse Glick Path: core/src/main/java/hudson/model/listeners/ItemListener.java http://jenkins-ci.org/commit/jenkins/6825121f06d6427304fd5149531216ecae6fdf93 Log: JENKINS-21224 Defend against exceptions in listeners, for now just for ItemListener. java.lang.RuntimeException: Unable to copy /…/jobs/…/config.xml at hudson.plugins.jobConfigHistory.FileHistoryDao.createNewHistoryEntryAndCopyConfig(FileHistoryDao.java:252) at hudson.plugins.jobConfigHistory.FileHistoryDao.createNewItem(FileHistoryDao.java:238) at hudson.plugins.jobConfigHistory.JobConfigHistoryJobListener.onCreated(JobConfigHistoryJobListener.java:31) at hudson.model.listeners.ItemListener.fireOnCreated(ItemListener.java:161) at jenkins.model.Jenkins.putItem(Jenkins.java:2483) at … Caused by: java.io.FileNotFoundException: /…/jobs/…/config.xml (No such file or directory) at java.io.FileInputStream.open(Native Method) at java.io.FileInputStream.<init>(FileInputStream.java:120) at hudson.plugins.jobConfigHistory.FileHistoryDao.copyConfigFile(FileHistoryDao.java:178) at hudson.plugins.jobConfigHistory.FileHistoryDao.createNewHistoryEntryAndCopyConfig(FileHistoryDao.java:250) ... 108 more

          dogfood added a comment -

          Integrated in jenkins_main_trunk #3723
          JENKINS-21224 Defend against exceptions in listeners, for now just for ItemListener. (Revision 6825121f06d6427304fd5149531216ecae6fdf93)

          Result = SUCCESS
          Jesse Glick : 6825121f06d6427304fd5149531216ecae6fdf93
          Files :

          • core/src/main/java/hudson/model/listeners/ItemListener.java

          dogfood added a comment - Integrated in jenkins_main_trunk #3723 JENKINS-21224 Defend against exceptions in listeners, for now just for ItemListener. (Revision 6825121f06d6427304fd5149531216ecae6fdf93) Result = SUCCESS Jesse Glick : 6825121f06d6427304fd5149531216ecae6fdf93 Files : core/src/main/java/hudson/model/listeners/ItemListener.java

          Code changed in jenkins
          User: Jesse Glick
          Path:
          core/src/main/java/hudson/model/listeners/ItemListener.java
          http://jenkins-ci.org/commit/jenkins/b70313476a86813417b9197555780622cf5170b8
          Log:
          JENKINS-21224 Defend against exceptions in listeners, for now just for ItemListener.
          java.lang.RuntimeException: Unable to copy /…/jobs/…/config.xml
          at hudson.plugins.jobConfigHistory.FileHistoryDao.createNewHistoryEntryAndCopyConfig(FileHistoryDao.java:252)
          at hudson.plugins.jobConfigHistory.FileHistoryDao.createNewItem(FileHistoryDao.java:238)
          at hudson.plugins.jobConfigHistory.JobConfigHistoryJobListener.onCreated(JobConfigHistoryJobListener.java:31)
          at hudson.model.listeners.ItemListener.fireOnCreated(ItemListener.java:161)
          at jenkins.model.Jenkins.putItem(Jenkins.java:2483)
          at …
          Caused by: java.io.FileNotFoundException: /…/jobs/…/config.xml (No such file or directory)
          at java.io.FileInputStream.open(Native Method)
          at java.io.FileInputStream.<init>(FileInputStream.java:120)
          at hudson.plugins.jobConfigHistory.FileHistoryDao.copyConfigFile(FileHistoryDao.java:178)
          at hudson.plugins.jobConfigHistory.FileHistoryDao.createNewHistoryEntryAndCopyConfig(FileHistoryDao.java:250)
          ... 108 more
          (cherry picked from commit 6825121f06d6427304fd5149531216ecae6fdf93)

          SCM/JIRA link daemon added a comment - Code changed in jenkins User: Jesse Glick Path: core/src/main/java/hudson/model/listeners/ItemListener.java http://jenkins-ci.org/commit/jenkins/b70313476a86813417b9197555780622cf5170b8 Log: JENKINS-21224 Defend against exceptions in listeners, for now just for ItemListener. java.lang.RuntimeException: Unable to copy /…/jobs/…/config.xml at hudson.plugins.jobConfigHistory.FileHistoryDao.createNewHistoryEntryAndCopyConfig(FileHistoryDao.java:252) at hudson.plugins.jobConfigHistory.FileHistoryDao.createNewItem(FileHistoryDao.java:238) at hudson.plugins.jobConfigHistory.JobConfigHistoryJobListener.onCreated(JobConfigHistoryJobListener.java:31) at hudson.model.listeners.ItemListener.fireOnCreated(ItemListener.java:161) at jenkins.model.Jenkins.putItem(Jenkins.java:2483) at … Caused by: java.io.FileNotFoundException: /…/jobs/…/config.xml (No such file or directory) at java.io.FileInputStream.open(Native Method) at java.io.FileInputStream.<init>(FileInputStream.java:120) at hudson.plugins.jobConfigHistory.FileHistoryDao.copyConfigFile(FileHistoryDao.java:178) at hudson.plugins.jobConfigHistory.FileHistoryDao.createNewHistoryEntryAndCopyConfig(FileHistoryDao.java:250) ... 108 more (cherry picked from commit 6825121f06d6427304fd5149531216ecae6fdf93)

          dogfood added a comment -

          Integrated in jenkins_main_trunk #4292
          JENKINS-21224 Defend against exceptions in listeners, for now just for ItemListener. (Revision b70313476a86813417b9197555780622cf5170b8)

          Result = UNSTABLE
          ogondza : b70313476a86813417b9197555780622cf5170b8
          Files :

          • core/src/main/java/hudson/model/listeners/ItemListener.java

          dogfood added a comment - Integrated in jenkins_main_trunk #4292 JENKINS-21224 Defend against exceptions in listeners, for now just for ItemListener. (Revision b70313476a86813417b9197555780622cf5170b8) Result = UNSTABLE ogondza : b70313476a86813417b9197555780622cf5170b8 Files : core/src/main/java/hudson/model/listeners/ItemListener.java

            jglick Jesse Glick
            jglick Jesse Glick
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: