mattyb149 commented on a change in pull request #5116:
URL: https://github.com/apache/nifi/pull/5116#discussion_r646734198



##########
File path: 
nifi-nar-bundles/nifi-scripting-bundle/nifi-scripting-processors/src/main/java/org/apache/nifi/rules/handlers/script/ScriptedActionHandler.java
##########
@@ -190,53 +184,63 @@ public void onEnabled(final ConfigurationContext context) 
{
         super.onEnabled(context);
 
         // Call an non-interface method onEnabled(context), to allow a 
scripted ActionHandler the chance to set up as necessary
-        final Invocable invocable = (Invocable) scriptEngine;
-        if (configurationContext != null) {
-            try {
-                // Get the actual object from the script engine, versus the 
proxy stored in ActionHandler. The object may have additional methods,
-                // where ActionHandler is a proxied interface
-                final Object obj = scriptEngine.get("actionHandler");
-                if (obj != null) {
-                    try {
-                        invocable.invokeMethod(obj, "onEnabled", context);
-                    } catch (final NoSuchMethodException nsme) {
-                        if (getLogger().isDebugEnabled()) {
-                            getLogger().debug("Configured script ActionHandler 
does not contain an onEnabled() method.");
+        if (scriptRunner != null) {
+            final ScriptEngine scriptEngine = scriptRunner.getScriptEngine();
+            final Invocable invocable = (Invocable) scriptEngine;
+            if (configurationContext != null) {
+                try {
+                    // Get the actual object from the script engine, versus 
the proxy stored in ActionHandler. The object may have additional methods,
+                    // where ActionHandler is a proxied interface
+                    final Object obj = 
scriptRunner.getScriptEngine().get("actionHandler");
+                    if (obj != null) {
+                        try {
+                            invocable.invokeMethod(obj, "onEnabled", context);
+                        } catch (final NoSuchMethodException nsme) {
+                            if (getLogger().isDebugEnabled()) {
+                                getLogger().debug("Configured script 
ActionHandler does not contain an onEnabled() method.");
+                            }
                         }
+                    } else {
+                        throw new ScriptException("No ActionHandler was 
defined by the script.");
                     }
-                } else {
-                    throw new ScriptException("No ActionHandler was defined by 
the script.");
+                } catch (ScriptException se) {
+                    throw new ProcessException("Error executing 
onEnabled(context) method", se);
                 }
-            } catch (ScriptException se) {
-                throw new ProcessException("Error executing onEnabled(context) 
method", se);
             }
+        } else {
+            throw new ProcessException("Error creating ScriptRunner");
         }

Review comment:
       Looks like a number of scripted components use this same pattern (they 
have to get the Object from the script engine instead of using a proxied object 
that only lets you invoke the interface method). I think we should refactor 
those under a separate improvement Jira




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to