summaryrefslogtreecommitdiff
path: root/javaunohelper
diff options
context:
space:
mode:
authorNoel Grandin <noel@peralex.com>2014-12-12 10:58:38 +0200
committerNoel Grandin <noelgrandin@gmail.com>2014-12-15 06:49:02 +0000
commit86c8e81178bae50b2de7591fc1cf53cd4d821363 (patch)
tree8c0eb65d868e471ed64bb6bd9dcc7181156309ba /javaunohelper
parente5a03da8eb02c333502d6b427625e7bf554ff203 (diff)
stronger checks when creating Java UNO components
check the visibility of construction method at load time for Java UNO components. This means that we get more informative errors at startup, instead of failures much later on when we actually create the component. Change-Id: I08cd16875cf53cfeeef7e8954ecd0d3177d70eb5 Reviewed-on: https://gerrit.libreoffice.org/13446 Reviewed-by: Noel Grandin <noelgrandin@gmail.com> Tested-by: Noel Grandin <noelgrandin@gmail.com>
Diffstat (limited to 'javaunohelper')
-rw-r--r--javaunohelper/com/sun/star/lib/uno/helper/Factory.java50
1 files changed, 41 insertions, 9 deletions
diff --git a/javaunohelper/com/sun/star/lib/uno/helper/Factory.java b/javaunohelper/com/sun/star/lib/uno/helper/Factory.java
index 89cf42e3703a..056d9549d552 100644
--- a/javaunohelper/com/sun/star/lib/uno/helper/Factory.java
+++ b/javaunohelper/com/sun/star/lib/uno/helper/Factory.java
@@ -119,48 +119,80 @@ public class Factory
private final String m_impl_name;
private final String [] m_supported_services;
private final Class<?> m_impl_class;
- private java.lang.reflect.Method m_method;
- private java.lang.reflect.Constructor m_ctor;
+ private final java.lang.reflect.Method m_method;
+ private final java.lang.reflect.Constructor m_ctor;
private Factory(
Class impl_class, String impl_name, String supported_services [] )
+ throws com.sun.star.uno.DeploymentException
{
m_impl_name = impl_name;
m_supported_services = supported_services;
m_impl_class = impl_class;
- m_method = null;
- m_ctor = null;
Class params [] = new Class [] { XComponentContext.class };
+ if (!java.lang.reflect.Modifier.isPublic( impl_class.getModifiers() ))
+ {
+ throw new com.sun.star.uno.DeploymentException("class " + impl_class + " is not public");
+ }
+
+ java.lang.reflect.Method tmpMethod = null;
try
{
// seeking for "public static Object __create( XComponentContext )"
- m_method = m_impl_class.getMethod( "__create", params );
- int mod = m_method.getModifiers();
- if (!m_method.getReturnType().equals( Object.class ) ||
+ tmpMethod = m_impl_class.getMethod( "__create", params );
+ int mod = tmpMethod.getModifiers();
+ if (!tmpMethod.getReturnType().equals( Object.class ) ||
!java.lang.reflect.Modifier.isStatic( mod ) ||
!java.lang.reflect.Modifier.isPublic( mod ))
{
- m_method = null;
+ tmpMethod = null;
}
}
catch (Exception exc)
{
}
+ m_method = tmpMethod;
+
+ java.lang.reflect.Constructor tmpCtor = null;
if (null == m_method)
{
try
{
// ctor with context
- m_ctor = m_impl_class.getConstructor( params );
+ tmpCtor = m_impl_class.getConstructor( params );
}
catch (Exception exc)
{
+ }
+ if (tmpCtor != null)
+ {
+ if (!java.lang.reflect.Modifier.isPublic( tmpCtor.getModifiers() ))
+ {
+ throw new com.sun.star.uno.DeploymentException("constructor with XComponentContext param for class " + impl_class + " is not public");
+ }
+ }
+ else
+ {
// else take default ctor
+ java.lang.reflect.Constructor defaultCtor;
+ try
+ {
+ defaultCtor = m_impl_class.getConstructor(new Class[0]);
+ }
+ catch (Exception exc2)
+ {
+ throw new com.sun.star.uno.DeploymentException(exc2, "class " + impl_class + " has no means of creating it, cannot find a __create method or a useful constructor.");
+ }
+ if (!java.lang.reflect.Modifier.isPublic( defaultCtor.getModifiers() ))
+ {
+ throw new com.sun.star.uno.DeploymentException("default constructor for class " + impl_class + " is not public");
+ }
}
}
+ m_ctor = tmpCtor;
}