Index: trunk/modules/jndi/src/main/java/javax/naming/CompoundName.java =================================================================== --- trunk/modules/jndi/src/main/java/javax/naming/CompoundName.java (revision 427412) +++ trunk/modules/jndi/src/main/java/javax/naming/CompoundName.java (working copy) @@ -661,7 +661,10 @@ } public Name add(String element) throws InvalidNameException { - elem.add(element); + if (element == null) { + throw new InvalidNameException("A flat name can only have a single component"); + } + elem.add(element); return this; } @@ -678,6 +681,9 @@ * this CompoundName becoming invalid. */ public Name add(int index, String element) throws InvalidNameException { + if (element == null) { + throw new InvalidNameException("A flat name can only zero or one component"); + } validateIndex(index, true); elem.add(index, element); return this; Index: trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/CompoundNameTest.java =================================================================== --- trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/CompoundNameTest.java (revision 427412) +++ trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/CompoundNameTest.java (working copy) @@ -1114,7 +1114,12 @@ CompoundName name; name = new CompoundName("", props); - name.add(null); + try { + name.add(null); + fail("InvalidNameException expected"); + } catch (InvalidNameException e) { + //expected + } } public void testAdd_Indexed() throws InvalidNameException { @@ -1146,7 +1151,21 @@ CompoundName name; name = new CompoundName("", props); - name.add(0, null); + try { + name.add(0, null); + fail("InvalidNameException expected"); + } catch (InvalidNameException e) { + //expected + } + + // regression test for HARMONY-1021 + name = new CompoundName("", props); + try { + name.add(11, null); + fail("InvalidNameException expected"); + } catch (InvalidNameException e) { + //expected + } } public void testRemove() throws InvalidNameException {