Uploaded image for project: 'Camel'
  1. Camel
  2. CAMEL-6416

ScriptBuilder Some scripting are exception lost

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 2.10.4
    • Fix Version/s: 2.10.7, 2.11.1, 2.12.0
    • Component/s: camel-script
    • Labels:
      None
    • Estimated Complexity:
      Novice

      Description

      Hello,

      A little bug in ScriptBuilder class cause some script errors to be lost and replaced by a NullPointerException :

      Encountered Exception
      Caused by: java.lang.NullPointerException
      	at org.apache.camel.builder.script.ScriptBuilder.createScriptEvaluationException(ScriptBuilder.java:418)
      	at org.apache.camel.builder.script.ScriptBuilder.evaluateScript(ScriptBuilder.java:348)
      	at org.apache.camel.builder.script.ScriptBuilder.evaluate(ScriptBuilder.java:92)
      	at org.apache.camel.builder.script.ScriptBuilder.evaluate(ScriptBuilder.java:96)
      

      The problem occurs in evaluateScript method (line 336 to 352) :

      ScriptBuilder.evaluateScript
          protected synchronized Object evaluateScript(Exchange exchange) {
              try {
                  getScriptContext();
                  populateBindings(getEngine(), exchange);
                  addScriptEngineArguments(getEngine(), exchange);
                  Object result = runScript(exchange);
                  LOG.debug("The script evaluation result is: {}", result);
                  return result;
              } catch (ScriptException e) {
                  if (LOG.isDebugEnabled()) {
                      LOG.debug("Script evaluation failed: " + e.getMessage(), e);
                  }
                  throw createScriptEvaluationException(e.getCause());
              } catch (IOException e) {
                  throw createScriptEvaluationException(e);
              }
          }
      

      We can see the following line (348) :
      throw createScriptEvaluationException(e.getCause());

      In some cases, the exception cause is null and the error message become very unclear.

      A simple workaround would be to write something like this :

      if (e.getCause() == null) {
          throw createScriptEvaluationException(e);
      } else {
          throw createScriptEvaluationException(e.getCause());
      }
      

      I don't have some GIT software, so I could not provide a patch, sorry for that

      Regards

        Attachments

          Activity

            People

            • Assignee:
              njiang Willem Jiang
              Reporter:
              fkocik Fabien KOCIK
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Time Tracking

                Estimated:
                Original Estimate - 1h
                1h
                Remaining:
                Remaining Estimate - 1h
                1h
                Logged:
                Time Spent - Not Specified
                Not Specified