Kaydet (Commit) 5b78551d authored tarafından Stephan Bergmann's avatar Stephan Bergmann

Related tdf#99272: Prevent bogus com.sun.star.uno.Type(Short[].class) etc.

...so that the JNI UNO bridge will not accidentally reinterpret a Short[] as a
short[].  <https://wiki.openoffice.org/wiki/Uno/Java/Specifications/Type_Mapping>
makes it clear that the former is not a valid Java representation for UNO type
"sequence of short".

Needed one fix in bogus test code.  Also fixed the two bogus places in odk/examples
mentioned in f53e4272 "Resolves: tdf#99272 new
Short[] used instead of new short[]".

Change-Id: I8321eb1294ec77b3a9bf73cafb6e7fe337157bb7
üst 86ab6471
...@@ -86,7 +86,7 @@ class SalesFilter implements XActionListener, XPropertyChangeListener, XResetLis ...@@ -86,7 +86,7 @@ class SalesFilter implements XActionListener, XPropertyChangeListener, XResetLis
m_xFilterList.setPropertyValue( "Dropdown", Boolean.TRUE ); m_xFilterList.setPropertyValue( "Dropdown", Boolean.TRUE );
m_xFilterList.setPropertyValue( "LineCount", Short.valueOf( (short)11 ) ); m_xFilterList.setPropertyValue( "LineCount", Short.valueOf( (short)11 ) );
m_xFilterList.setPropertyValue( "StringItemList", new String[] { "ever (means no filter)", "this morning", "1 week ago", "1 month ago", "1 year ago", "<other>" } ); m_xFilterList.setPropertyValue( "StringItemList", new String[] { "ever (means no filter)", "this morning", "1 week ago", "1 month ago", "1 year ago", "<other>" } );
m_xFilterList.setPropertyValue( "DefaultSelection", new Short[] { Short.valueOf( (short)0 ) } ); m_xFilterList.setPropertyValue( "DefaultSelection", new short[] { (short)0 } );
m_xApplyFilter.setPropertyValue( "Label", "Apply Filter" ); m_xApplyFilter.setPropertyValue( "Label", "Apply Filter" );
......
...@@ -99,7 +99,7 @@ public class SystemDialog { ...@@ -99,7 +99,7 @@ public class SystemDialog {
// choose the template that defines the capabilities of the filepicker dialog // choose the template that defines the capabilities of the filepicker dialog
XInitialization xInitialize = UnoRuntime.queryInterface(XInitialization.class, xFilePicker); XInitialization xInitialize = UnoRuntime.queryInterface(XInitialization.class, xFilePicker);
Short[] listAny = new Short[] { Short.valueOf(com.sun.star.ui.dialogs.TemplateDescription.FILESAVE_AUTOEXTENSION)}; short[] listAny = new short[] { com.sun.star.ui.dialogs.TemplateDescription.FILESAVE_AUTOEXTENSION };
xInitialize.initialize(listAny); xInitialize.initialize(listAny);
// add a control to the dialog to add the extension automatically to the filename... // add a control to the dialog to add the extension automatically to the filename...
......
...@@ -78,65 +78,81 @@ public class Type { ...@@ -78,65 +78,81 @@ public class Type {
TYPE_NAME_ANY TYPE_NAME_ANY
}; };
private static final HashMap<Class<?>, TypeClass[]> __javaClassToTypeClass = new HashMap<Class<?>, TypeClass[]>(); private static final class TypeInfo {
TypeInfo(
TypeClass thePrimary, TypeClass theAlternative,
boolean theSequenceComponentType)
{
primary = thePrimary;
alternative = theAlternative;
sequenceComponentType = theSequenceComponentType;
}
final TypeClass primary;
final TypeClass alternative;
final boolean sequenceComponentType;
}
private static final HashMap<Class<?>, TypeInfo> __javaClassToTypeClass =
new HashMap<Class<?>, TypeInfo>();
static { static {
__javaClassToTypeClass.put( __javaClassToTypeClass.put(
void.class, new TypeClass[] { TypeClass.VOID, TypeClass.VOID }); void.class, new TypeInfo(TypeClass.VOID, TypeClass.VOID, false));
__javaClassToTypeClass.put( __javaClassToTypeClass.put(
Void.class, new TypeClass[] { TypeClass.VOID, TypeClass.VOID }); Void.class, new TypeInfo(TypeClass.VOID, TypeClass.VOID, false));
__javaClassToTypeClass.put( __javaClassToTypeClass.put(
boolean.class, boolean.class,
new TypeClass[] { TypeClass.BOOLEAN, TypeClass.BOOLEAN }); new TypeInfo(TypeClass.BOOLEAN, TypeClass.BOOLEAN, true));
__javaClassToTypeClass.put( __javaClassToTypeClass.put(
Boolean.class, Boolean.class,
new TypeClass[] { TypeClass.BOOLEAN, TypeClass.BOOLEAN }); new TypeInfo(TypeClass.BOOLEAN, TypeClass.BOOLEAN, false));
__javaClassToTypeClass.put( __javaClassToTypeClass.put(
byte.class, new TypeClass[] { TypeClass.BYTE, TypeClass.BYTE }); byte.class, new TypeInfo(TypeClass.BYTE, TypeClass.BYTE, true));
__javaClassToTypeClass.put( __javaClassToTypeClass.put(
Byte.class, new TypeClass[] { TypeClass.BYTE, TypeClass.BYTE }); Byte.class, new TypeInfo(TypeClass.BYTE, TypeClass.BYTE, false));
__javaClassToTypeClass.put( __javaClassToTypeClass.put(
short.class, short.class,
new TypeClass[] { TypeClass.SHORT, TypeClass.UNSIGNED_SHORT }); new TypeInfo(TypeClass.SHORT, TypeClass.UNSIGNED_SHORT, true));
__javaClassToTypeClass.put( __javaClassToTypeClass.put(
Short.class, Short.class,
new TypeClass[] { TypeClass.SHORT, TypeClass.UNSIGNED_SHORT }); new TypeInfo(TypeClass.SHORT, TypeClass.UNSIGNED_SHORT, false));
__javaClassToTypeClass.put( __javaClassToTypeClass.put(
int.class, int.class,
new TypeClass[] { TypeClass.LONG, TypeClass.UNSIGNED_LONG }); new TypeInfo(TypeClass.LONG, TypeClass.UNSIGNED_LONG, true));
__javaClassToTypeClass.put( __javaClassToTypeClass.put(
Integer.class, Integer.class,
new TypeClass[] { TypeClass.LONG, TypeClass.UNSIGNED_LONG }); new TypeInfo(TypeClass.LONG, TypeClass.UNSIGNED_LONG, false));
__javaClassToTypeClass.put( __javaClassToTypeClass.put(
long.class, long.class,
new TypeClass[] { TypeClass.HYPER, TypeClass.UNSIGNED_HYPER }); new TypeInfo(TypeClass.HYPER, TypeClass.UNSIGNED_HYPER, true));
__javaClassToTypeClass.put( __javaClassToTypeClass.put(
Long.class, Long.class,
new TypeClass[] { TypeClass.HYPER, TypeClass.UNSIGNED_HYPER }); new TypeInfo(TypeClass.HYPER, TypeClass.UNSIGNED_HYPER, false));
__javaClassToTypeClass.put( __javaClassToTypeClass.put(
float.class, new TypeClass[] { TypeClass.FLOAT, TypeClass.FLOAT }); float.class, new TypeInfo(TypeClass.FLOAT, TypeClass.FLOAT, true));
__javaClassToTypeClass.put( __javaClassToTypeClass.put(
Float.class, new TypeClass[] { TypeClass.FLOAT, TypeClass.FLOAT }); Float.class, new TypeInfo(TypeClass.FLOAT, TypeClass.FLOAT, false));
__javaClassToTypeClass.put( __javaClassToTypeClass.put(
double.class, double.class,
new TypeClass[] { TypeClass.DOUBLE, TypeClass.DOUBLE }); new TypeInfo(TypeClass.DOUBLE, TypeClass.DOUBLE, true));
__javaClassToTypeClass.put( __javaClassToTypeClass.put(
Double.class, Double.class,
new TypeClass[] { TypeClass.DOUBLE, TypeClass.DOUBLE }); new TypeInfo(TypeClass.DOUBLE, TypeClass.DOUBLE, false));
__javaClassToTypeClass.put( __javaClassToTypeClass.put(
char.class, new TypeClass[] { TypeClass.CHAR, TypeClass.CHAR }); char.class, new TypeInfo(TypeClass.CHAR, TypeClass.CHAR, true));
__javaClassToTypeClass.put( __javaClassToTypeClass.put(
Character.class, Character.class,
new TypeClass[] { TypeClass.CHAR, TypeClass.CHAR }); new TypeInfo(TypeClass.CHAR, TypeClass.CHAR, false));
__javaClassToTypeClass.put( __javaClassToTypeClass.put(
String.class, String.class,
new TypeClass[] { TypeClass.STRING, TypeClass.STRING }); new TypeInfo(TypeClass.STRING, TypeClass.STRING, true));
__javaClassToTypeClass.put( __javaClassToTypeClass.put(
Type.class, new TypeClass[] { TypeClass.TYPE, TypeClass.TYPE }); Type.class, new TypeInfo(TypeClass.TYPE, TypeClass.TYPE, true));
__javaClassToTypeClass.put( __javaClassToTypeClass.put(
Any.class, new TypeClass[] { TypeClass.ANY, TypeClass.ANY }); Any.class, new TypeInfo(TypeClass.ANY, TypeClass.ANY, true));
__javaClassToTypeClass.put( __javaClassToTypeClass.put(
Object.class, Object.class,
new TypeClass[] { TypeClass.ANY, TypeClass.INTERFACE }); new TypeInfo(TypeClass.ANY, TypeClass.INTERFACE, true));
} }
public static final Type VOID = new Type(void.class); public static final Type VOID = new Type(void.class);
...@@ -162,7 +178,7 @@ public class Type { ...@@ -162,7 +178,7 @@ public class Type {
* Constructs a new <code>Type</code> which defaults to <code>VOID</code>. * Constructs a new <code>Type</code> which defaults to <code>VOID</code>.
*/ */
public Type() { public Type() {
init(null, void.class, false, false); init(null, void.class, false, false, false);
} }
/** /**
...@@ -190,7 +206,7 @@ public class Type { ...@@ -190,7 +206,7 @@ public class Type {
* <code>null</code>. * <code>null</code>.
*/ */
public Type(Class<?> zClass) { public Type(Class<?> zClass) {
init(null, zClass, false, false); init(null, zClass, false, false, false);
} }
/** /**
...@@ -244,7 +260,13 @@ public class Type { ...@@ -244,7 +260,13 @@ public class Type {
* @since UDK 3.2.0 * @since UDK 3.2.0
*/ */
public Type(Class<?> zClass, boolean alternative) { public Type(Class<?> zClass, boolean alternative) {
init(null, zClass, alternative, false); init(null, zClass, alternative, false, false);
}
private Type(
Class<?> zClass, boolean alternative, boolean sequenceComponentType)
{
init(null, zClass, alternative, false, sequenceComponentType);
} }
/** /**
...@@ -282,7 +304,7 @@ public class Type { ...@@ -282,7 +304,7 @@ public class Type {
init( init(
typeName, typeName,
Class.forName(i < 0 ? typeName : typeName.substring(0, i)), Class.forName(i < 0 ? typeName : typeName.substring(0, i)),
false, i >= 0); false, i >= 0, false);
} catch (ClassNotFoundException e) { } catch (ClassNotFoundException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
...@@ -449,14 +471,19 @@ public class Type { ...@@ -449,14 +471,19 @@ public class Type {
} }
private void init( private void init(
String name, Class<?> zClass, boolean alternative, boolean arguments) String name, Class<?> zClass, boolean alternative, boolean arguments,
boolean sequenceComponentType)
{ {
TypeClass[] tc = __javaClassToTypeClass.get(zClass); TypeInfo info = __javaClassToTypeClass.get(zClass);
if (tc != null) { if (info != null) {
// tc only contains primitive type classes, except for if (sequenceComponentType && !info.sequenceComponentType) {
throw new IllegalArgumentException(
zClass + " cannot be sequence component type");
}
// info only contains primitive type classes, except for
// TypeClass.INTERFACE, which stands for XInterface (the alternative // TypeClass.INTERFACE, which stands for XInterface (the alternative
// interpretation of java.lang.Object): // interpretation of java.lang.Object):
_typeClass = tc[alternative ? 1 : 0]; _typeClass = alternative ? info.alternative : info.primary;
_typeName = _typeClass == TypeClass.INTERFACE _typeName = _typeClass == TypeClass.INTERFACE
? XInterface.class.getName() ? XInterface.class.getName()
: __typeClassToTypeName[_typeClass.getValue()]; : __typeClassToTypeName[_typeClass.getValue()];
...@@ -465,7 +492,7 @@ public class Type { ...@@ -465,7 +492,7 @@ public class Type {
// java.lang.Boolean.class); getZClass will later calculate the // java.lang.Boolean.class); getZClass will later calculate the
// correct class when needed // correct class when needed
} else if (zClass.isArray()) { } else if (zClass.isArray()) {
Type t = new Type(zClass.getComponentType(), alternative); Type t = new Type(zClass.getComponentType(), alternative, true);
_typeClass = t.getTypeClass() != TypeClass.UNKNOWN _typeClass = t.getTypeClass() != TypeClass.UNKNOWN
? TypeClass.SEQUENCE : TypeClass.UNKNOWN; ? TypeClass.SEQUENCE : TypeClass.UNKNOWN;
_typeName = "[]" + t.getTypeName(); _typeName = "[]" + t.getTypeName();
......
...@@ -76,7 +76,11 @@ public final class Type_Test { ...@@ -76,7 +76,11 @@ public final class Type_Test {
assertSame(boolean.class, new Type(boolean.class).getZClass()); assertSame(boolean.class, new Type(boolean.class).getZClass());
assertSame(boolean.class, new Type(Boolean.class).getZClass()); assertSame(boolean.class, new Type(Boolean.class).getZClass());
assertSame(boolean[].class, new Type(boolean[].class).getZClass()); assertSame(boolean[].class, new Type(boolean[].class).getZClass());
assertSame(boolean[].class, new Type(Boolean[].class).getZClass());
try {
new Type(Boolean[].class);
fail();
} catch (java.lang.RuntimeException e) {}
} }
@Test public void testIsSupertypeOf() { @Test public void testIsSupertypeOf() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment