Index: Bidi.java =================================================================== --- Bidi.java (revision 427077) +++ Bidi.java (working copy) @@ -132,6 +132,15 @@ */ public Bidi(char[] text, int textStart, byte[] embeddings, int embStart, int paragraphLength, int flags) { +// if (textStart < 0) { +// throw new IllegalArgumentException("Negative textStart value " + textStart); +// } +// if (embStart < 0) { +// throw new IllegalArgumentException("Negative embStart value " + embStart); +// } +// if (paragraphLength < 0) { +// throw new IllegalArgumentException("Negative paragraph length " + paragraphLength); +// } long pBidi = createUBiDi(text, textStart, embeddings, embStart, paragraphLength, flags); readBidiInfo(pBidi); @@ -177,21 +186,23 @@ if (embeddings.length < embStart + paragraphLength) { throw new IllegalArgumentException(); } - Bidi temp = new Bidi(text, textStart, null, 0, paragraphLength, - flags); - realEmbeddings = new byte[paragraphLength]; - System.arraycopy(temp.offsetLevel, 0, realEmbeddings, 0, - paragraphLength); - for (int i = 0; i < paragraphLength; i++) { - byte e = embeddings[i]; - if (e < 0) { - realEmbeddings[i] = (byte) (BidiWrapper.UBIDI_LEVEL_OVERRIDE - e); - } else if (e > 0) { - realEmbeddings[i] = e; - } else { - realEmbeddings[i] |= (byte) BidiWrapper.UBIDI_LEVEL_OVERRIDE; +// if (paragraphLength > 0) { + Bidi temp = new Bidi(text, textStart, null, 0, paragraphLength, + flags); + realEmbeddings = new byte[paragraphLength]; + System.arraycopy(temp.offsetLevel, 0, realEmbeddings, 0, + paragraphLength); + for (int i = 0; i < paragraphLength; i++) { + byte e = embeddings[i]; + if (e < 0) { + realEmbeddings[i] = (byte) (BidiWrapper.UBIDI_LEVEL_OVERRIDE - e); + } else if (e > 0) { + realEmbeddings[i] = e; + } else { + realEmbeddings[i] |= (byte) BidiWrapper.UBIDI_LEVEL_OVERRIDE; + } } - } +// } } if (flags > 1 || flags < -2) { @@ -410,6 +421,9 @@ */ public static void reorderVisually(byte[] levels, int levelStart, Object[] objects, int objectStart, int count) { + if (count < 0) { + throw new IllegalArgumentException("count " + count + " must be >= 0"); + } try { byte[] realLevels = new byte[count]; System.arraycopy(levels, levelStart, realLevels, 0, count);