Bug 341963 - [metatype] StringIndexOutOfBoundsException when description or name attributes are an empty string
diff --git a/bundles/org.eclipse.equinox.compendium.tests/bundles_src/metatype/tb3/OSGI-INF/metatype/testfile.xml b/bundles/org.eclipse.equinox.compendium.tests/bundles_src/metatype/tb3/OSGI-INF/metatype/testfile.xml
index 4519a18..fce2209 100644
--- a/bundles/org.eclipse.equinox.compendium.tests/bundles_src/metatype/tb3/OSGI-INF/metatype/testfile.xml
+++ b/bundles/org.eclipse.equinox.compendium.tests/bundles_src/metatype/tb3/OSGI-INF/metatype/testfile.xml
@@ -8,7 +8,13 @@
<AD cardinality="0" id="password2" type="Password"/>
<AD cardinality="0" default="Hello\, world!" id="string1" type="String"/>
</OCD>
+ <OCD id="ocd2" name="" description="">
+ <AD id="ad1" name="" description="" type="String"/>
+ </OCD>
<Designate pid="org.eclipse.equinox.metatype.tests.tb3">
<Object ocdref="ocd1"/>
</Designate>
+ <Designate pid="ocd2">
+ <Object ocdref="ocd2"/>
+ </Designate>
</md:MetaData>
diff --git a/bundles/org.eclipse.equinox.compendium.tests/src/org/eclipse/equinox/metatype/tests/BugTests.java b/bundles/org.eclipse.equinox.compendium.tests/src/org/eclipse/equinox/metatype/tests/BugTests.java
index 35fa588..ea51857 100644
--- a/bundles/org.eclipse.equinox.compendium.tests/src/org/eclipse/equinox/metatype/tests/BugTests.java
+++ b/bundles/org.eclipse.equinox.compendium.tests/src/org/eclipse/equinox/metatype/tests/BugTests.java
@@ -50,6 +50,26 @@
assertValidationPass(escape(getFirstDefaultValue(ad.getDefaultValue())), ad);
}
+ /*
+ * StringIndexOutOfBoundsException when description or name attributes are an empty string
+ */
+ public void test341963() {
+ MetaTypeInformation mti = metatype.getMetaTypeInformation(bundle);
+ assertNotNull("Metatype information not found", mti); //$NON-NLS-1$
+ ObjectClassDefinition ocd = mti.getObjectClassDefinition("ocd2", null); //$NON-NLS-1$
+ assertNotNull("Object class definition not found", ocd); //$NON-NLS-1$
+ assertEquals("Wrong name", "", ocd.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ assertEquals("Wrong description", "", ocd.getDescription()); //$NON-NLS-1$ //$NON-NLS-2$
+ AttributeDefinition[] ads = ocd.getAttributeDefinitions(ObjectClassDefinition.ALL);
+ assertNotNull("Attribute definitions not found", ads); //$NON-NLS-1$
+ assertEquals("Wrong number of attribute definitions", 1, ads.length); //$NON-NLS-1$
+
+ AttributeDefinition ad = findAttributeDefinitionById("ad1", ads); //$NON-NLS-1$
+ assertNotNull("Attribute definition not found", ad); //$NON-NLS-1$
+ assertEquals("Wrong name", "", ad.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ assertEquals("Wrong description", "", ad.getDescription()); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
protected void setUp() throws Exception {
super.setUp();
bundle = bundleInstaller.installBundle("tb3"); //$NON-NLS-1$
diff --git a/bundles/org.eclipse.equinox.metatype/src/org/eclipse/equinox/metatype/LocalizationElement.java b/bundles/org.eclipse.equinox.metatype/src/org/eclipse/equinox/metatype/LocalizationElement.java
index 6b3bda4..a440439 100644
--- a/bundles/org.eclipse.equinox.metatype/src/org/eclipse/equinox/metatype/LocalizationElement.java
+++ b/bundles/org.eclipse.equinox.metatype/src/org/eclipse/equinox/metatype/LocalizationElement.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2006 IBM Corporation and others.
+ * Copyright (c) 2005, 2011 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -35,7 +35,7 @@
return null;
}
- if ((key.charAt(0) == KEY_SIGN) && (key.length() > 1)) {
+ if ((key.length() > 1) && (key.charAt(0) == KEY_SIGN)) {
if (_rb != null) {
try {
String transfered = _rb.getString(key.substring(1));