[Libreoffice-commits] core.git: Branch 'libreoffice-6-0' - scripting/java

Stephan Bergmann sbergman at redhat.com
Fri Jun 15 19:54:44 UTC 2018


 scripting/java/com/sun/star/script/framework/provider/ClassLoaderFactory.java                     |    4 ++--
 scripting/java/com/sun/star/script/framework/provider/beanshell/ScriptEditorForBeanShell.java     |    5 ++---
 scripting/java/com/sun/star/script/framework/provider/beanshell/ScriptProviderForBeanShell.java   |    3 +--
 scripting/java/com/sun/star/script/framework/provider/javascript/ScriptProviderForJavaScript.java |    3 +--
 4 files changed, 6 insertions(+), 9 deletions(-)

New commits:
commit 9a1d26e3d9c9c02932e083cec9914e399eaf5d9c
Author: Stephan Bergmann <sbergman at redhat.com>
Date:   Fri Jun 15 15:55:37 2018 +0200

    Restore binary compatibility for ClassLoaderFactory
    
    As discussed in the mail thread starting at <http://mail-archives.apache.org/
    mod_mbox/openoffice-dev/201806.mbox/%3c651c8fee-b467-421c-eae1-a8710f41692c
    @apache.org%3e> "Just a little side note on the scripting framework ...",
    external code that uses the Java class
    com.sun.star.script.framework.provider.ClassLoaderFactory stopped working
    because LO changed that class in binary (and compile-time) incompatible ways
    over time.
    
    The class is not listed at
    <https://api.libreoffice.org/docs/java/ref/index.html> (and neither at
    <http://www.openoffice.org/api/docs/java/ref/overview-summary.html>), so it was
    not considered part of the stable URE interface.  But it is apparently used by
    external code, and it indeed seems to make sense that it is used by external
    code that implements scripting providers.  (A follow-up commit should therefore
    mark the class as part of the stable URE interface.  I keep that separate so
    that it is easier to backport this functional fix.)
    
    With ScriptProviderForooRexx.oxt from
    https://svn.code.sf.net/p/bsf4oorexx/code@r589 installed in LO, "Tools - Macros
    - Organize Macros - ooRexx... - My Macros - Create... - Library1 - OK -
    Create... - Macro1 - OK - Edit" failed due to
    
    > warn:cui.dialogs:21768:21768:cui/source/dialogs/scriptdlg.cxx:740: Caught exception trying to invoke N3com3sun4star3uno9ExceptionE msg: [jni_uno bridge error] UNO calling Java method invoke: non-UNO exception occurred: java.lang.NoSuchMethodError: com.sun.star.script.framework.provider.ClassLoaderFactory.getURLClassLoader(Lcom/sun/star/script/framework/container/ScriptMetaData;)Ljava/lang/ClassLoader;
    > java stack trace:
    > java.lang.NoSuchMethodError: com.sun.star.script.framework.provider.ClassLoaderFactory.getURLClassLoader(Lcom/sun/star/script/framework/container/ScriptMetaData;)Ljava/lang/ClassLoader;
    >       at com.sun.star.script.framework.provider.oorexx.ScriptEditorForooRexx.edit(ScriptEditorForooRexx.java:305)
    >       at com.sun.star.script.framework.browse.ScriptBrowseNode.invoke(ScriptBrowseNode.java:200)
    
    cae57d2e588a4b5a104171e022b00abcc1605775 "ClassLoader->URLClassLoader" (which
    this commit reverts) had changed the return type of the two getURLClassLoader
    overloads from ClassLoader to derived URLClassLoader (and ultimately only for
    cosmetic effect; it was leftover from a previous attempt at fixing a Coverity
    issue by using URLClassLoader.close(), but which is only available in Java 1.7,
    so the attempt had been reverted).  That caused the above failure.
    
    And 68cd011c907d00493bf2bfde531c1e244819596b "java: reduce scope, make some
    methods private" (which this commit also reverts) had changed the second
    getURLClassLoader overload (which is not called in the above scenario) from
    public to private, which is also a binary-incompatible change.
    
    Other commits removed throws clauses, which is only a compile-time issue but not
    a binary-incompatible change.  I left those changes in for now, but if need be
    they could also be reverted.
    
    Change-Id: I98f533d88c7c1580956c3c281e72a1c78fa3f56f
    Reviewed-on: https://gerrit.libreoffice.org/55873
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>

diff --git a/scripting/java/com/sun/star/script/framework/provider/ClassLoaderFactory.java b/scripting/java/com/sun/star/script/framework/provider/ClassLoaderFactory.java
index 73ba06938884..5434945ed41e 100644
--- a/scripting/java/com/sun/star/script/framework/provider/ClassLoaderFactory.java
+++ b/scripting/java/com/sun/star/script/framework/provider/ClassLoaderFactory.java
@@ -31,7 +31,7 @@ public class ClassLoaderFactory {
 
     private ClassLoaderFactory() {}
 
-    public static URLClassLoader getURLClassLoader(ScriptMetaData scriptData) {
+    public static ClassLoader getURLClassLoader(ScriptMetaData scriptData) {
         ClassLoader parent = scriptData.getClass().getClassLoader();
         URL[] classPath = scriptData.getClassPath();
         LogUtils.DEBUG("Classpath has length " + classPath.length);
@@ -43,7 +43,7 @@ public class ClassLoaderFactory {
         return getURLClassLoader(parent, classPath);
     }
 
-    private static URLClassLoader getURLClassLoader(ClassLoader parent,
+    public static ClassLoader getURLClassLoader(ClassLoader parent,
             URL[] classpath) {
         return new URLClassLoader(classpath, parent);
     }
diff --git a/scripting/java/com/sun/star/script/framework/provider/beanshell/ScriptEditorForBeanShell.java b/scripting/java/com/sun/star/script/framework/provider/beanshell/ScriptEditorForBeanShell.java
index 87553b7faaf0..32fa751351d0 100644
--- a/scripting/java/com/sun/star/script/framework/provider/beanshell/ScriptEditorForBeanShell.java
+++ b/scripting/java/com/sun/star/script/framework/provider/beanshell/ScriptEditorForBeanShell.java
@@ -35,7 +35,6 @@ import java.io.InputStream;
 import java.io.OutputStream;
 
 import java.net.URL;
-import java.net.URLClassLoader;
 
 import java.util.HashMap;
 import java.util.Map;
@@ -185,14 +184,14 @@ public class ScriptEditorForBeanShell implements ScriptEditor, ActionListener {
     public void edit(final XScriptContext context, ScriptMetaData entry) {
         if (entry != null) {
             try {
-                URLClassLoader cl = null;
+                ClassLoader cl = null;
 
                 try {
                     cl = ClassLoaderFactory.getURLClassLoader(entry);
                 } catch (Exception ignore) { // TODO re-examine error handling
                 }
 
-                final URLClassLoader theCl = cl;
+                final ClassLoader theCl = cl;
                 final URL url = entry.getSourceURL();
                 SwingInvocation.invoke(
                 new Runnable() {
diff --git a/scripting/java/com/sun/star/script/framework/provider/beanshell/ScriptProviderForBeanShell.java b/scripting/java/com/sun/star/script/framework/provider/beanshell/ScriptProviderForBeanShell.java
index 4caf64578800..2aabba71242b 100644
--- a/scripting/java/com/sun/star/script/framework/provider/beanshell/ScriptProviderForBeanShell.java
+++ b/scripting/java/com/sun/star/script/framework/provider/beanshell/ScriptProviderForBeanShell.java
@@ -50,7 +50,6 @@ import com.sun.star.uno.Type;
 import com.sun.star.uno.XComponentContext;
 
 import java.net.URL;
-import java.net.URLClassLoader;
 
 import java.util.StringTokenizer;
 
@@ -183,7 +182,7 @@ class ScriptImpl implements XScript {
         aOutParamIndex[0] = new short[0];
         aOutParam[0] = new Object[0];
 
-        URLClassLoader cl = null;
+        ClassLoader cl = null;
         URL sourceUrl = null;
 
         try {
diff --git a/scripting/java/com/sun/star/script/framework/provider/javascript/ScriptProviderForJavaScript.java b/scripting/java/com/sun/star/script/framework/provider/javascript/ScriptProviderForJavaScript.java
index fcd08cd2e9ca..9465a646f64d 100644
--- a/scripting/java/com/sun/star/script/framework/provider/javascript/ScriptProviderForJavaScript.java
+++ b/scripting/java/com/sun/star/script/framework/provider/javascript/ScriptProviderForJavaScript.java
@@ -45,7 +45,6 @@ import com.sun.star.script.provider.XScript;
 import com.sun.star.uno.XComponentContext;
 
 import java.net.URL;
-import java.net.URLClassLoader;
 
 import org.mozilla.javascript.Context;
 import org.mozilla.javascript.ImporterTopLevel;
@@ -182,7 +181,7 @@ class ScriptImpl implements XScript {
         aOutParamIndex[0] = new short[0];
         aOutParam[0] = new Object[0];
 
-        URLClassLoader cl = null;
+        ClassLoader cl = null;
 
         try {
             cl = ClassLoaderFactory.getURLClassLoader(metaData);


More information about the Libreoffice-commits mailing list