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

workflowLibs custom Exception with simple getters cause java to hog cpu

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: Minor Minor
    • None
    • Jenkins 2.7.1
      Ubuntu 14.04 64-bit
      java.runtime.name OpenJDK Runtime Environment
      java.runtime.version 1.7.0_101-b00

      If I create a custom exception class with simple getters and throw it in the pipeline script the build job stalls and java hogs all cpu in the server until killed. If the simple getters are commented out, the exception throwing and catching works fine.

      Steps to reproduce

      1. Put the following code to pipeline workflowLibs in path src/com/rohea/util/CustomException.groovy and push to Jenkins master git

      package com.rohea.util;
      
      public class CustomException extends Exception {
          private int errorCode;
          private String errorMessage;
          private String pipelineStage;
      
          public CustomException(String pipelineStage, String errorMessage, int errorCode) {
              this.pipelineStage = pipelineStage;
              this.errorCode = errorCode;
              this.errorMessage = errorMessage;
          }
      
          public String getFullMessage() {
              return this.pipelineStage + ' ' + this.errorMessage + ' errorCode: ' + this.errorCode;
          }
      
          // The existence of these methods causes Jenkins to go on an infinite loop
          // for some reason.
          public String getPipelineStage() {
              return this.pipelineStage;
          }
      
          public int getErrorCode() {
              return this.errorCode;
          }
      
          public String getErrorMessage() {
              return this.errorMessage;
          }
      }
      

      2. Create a pipeline job with following code for the script:

      node {
          try {
              errorFunction()
          } catch (com.rohea.util.CustomException exception) {
              echo 'Catched: ' + exception.getFullMessage()
          }
      }
      
      def errorFunction() {
          throw new com.rohea.util.CustomException('ErrorFunction', 'Error happened', 14)
      }
      

      3. Build the job

      4. The job hangs forever until forcefully killed in the pipeline stage

            Unassigned Unassigned
            hotoro Heikki Niiranen
            Votes:
            1 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: