Browse Source

Merge pull request #7919 from afishbeck/espJavaCrash

HPCC-14427 Catch and log JAVA exception when loading ESDL definitions

Reviewed-By: Richard Chapman <rchapman@hpccsystems.com>
Richard Chapman 9 years ago
parent
commit
97f1f0510c
2 changed files with 24 additions and 6 deletions
  1. 16 2
      esp/services/esdl_svc_engine/esdl_binding.cpp
  2. 8 4
      plugins/javaembed/javaembed.cpp

+ 16 - 2
esp/services/esdl_svc_engine/esdl_binding.cpp

@@ -259,8 +259,22 @@ void EsdlServiceImpl::configureJavaMethod(const char *method, IPropertyTree &ent
     if (!javaServiceMap.getValue(javaScopedClass))
     {
         VStringBuffer classPathOption("classpath=%s", classPath);
-        Owned<IEmbedServiceContext> srvctx = ensureJavaEmbeded().createServiceContext(javaScopedClass, EFimport, classPathOption);
-        javaServiceMap.setValue(javaScopedClass, srvctx.getClear());
+        try
+        {
+            Owned<IEmbedServiceContext> srvctx = ensureJavaEmbeded().createServiceContext(javaScopedClass, EFimport, classPathOption);
+            if (srvctx)
+                javaServiceMap.setValue(javaScopedClass, srvctx.getClear());
+            else
+            {
+                //Log error, but try again next reload, in case the java class is fixed
+                DBGLOG("ESDL binding - failed to load java class %s for target method %s", javaScopedClass.str(), method);
+            }
+        }
+        catch (IException *E)
+        {
+            DBGLOG(E, "DynamicESDL-JavaMethod:");
+            E->Release();
+        }
     }
 }
 

+ 8 - 4
plugins/javaembed/javaembed.cpp

@@ -3110,7 +3110,7 @@ class JavaEmbedServiceContext : public CInterfaceOf<IEmbedServiceContext>
 {
 public:
     JavaEmbedServiceContext(JavaThreadContext *_sharedCtx, const char *service, const char *_options)
-    : sharedCtx(_sharedCtx), Class(0), options(_options), className(service)
+    : sharedCtx(_sharedCtx), Class(0), options(_options), className(service), object(0)
     {
         StringArray opts;
         opts.appendList(options, ",");
@@ -3135,8 +3135,10 @@ public:
     }
     ~JavaEmbedServiceContext()
     {
-        sharedCtx->JNIenv->DeleteGlobalRef(object);
-        sharedCtx->JNIenv->DeleteGlobalRef(Class);
+        if (object)
+            sharedCtx->JNIenv->DeleteGlobalRef(object);
+        if (Class)
+            sharedCtx->JNIenv->DeleteGlobalRef(Class);
         // Pop local reference frame; explicitly frees all local
         // references made during that frame's lifetime
         sharedCtx->JNIenv->PopLocalFrame(NULL);
@@ -3149,9 +3151,9 @@ public:
         checkException();
         jstring methodString = sharedCtx->JNIenv->NewStringUTF(className);
         checkException();
+
         Class = (jclass) sharedCtx->JNIenv->NewGlobalRef(sharedCtx->JNIenv->CallObjectMethod(classLoader, loadClassMethod, methodString));
         checkException();
-
         jmethodID constructor = sharedCtx->JNIenv->GetMethodID(Class, "<init>", "()V");
         checkException();
         object = sharedCtx->JNIenv->NewGlobalRef(sharedCtx->JNIenv->NewObject(Class, constructor));
@@ -3159,6 +3161,8 @@ public:
     }
     virtual IEmbedFunctionContext *createFunctionContext(const char *function)
     {
+        if (!object)
+            return NULL;
         Owned<JavaEmbedImportContext> fctx = new JavaEmbedImportContext(queryContext(), object, options);
         fctx->importFunction(rtlUtf8Length(strlen(function), function), function);
         return fctx.getClear();