Community
Participate
Working Groups
Build ID: M20080911-1700 Looking at the javadocs it is not clear how the toCharArray family of methods in org.eclipse.jdt.core.Signature handles empty char[] as input. The docs only say: @exception IllegalArgumentException if the signature is not syntactically correct One could argue that an empty string cannot contain syntax errors. Digging into the implementation one hint is found in appendTypeSignature: // need a minimum 1 char The following snippet from toCharArray(char[]) looks confusing to me: int sigLength = signature.length; if (sigLength == 0 || signature[0] == C_PARAM_START || signature[0] == C_GENERIC_START) { return toCharArray(signature, CharOperation.NO_CHAR, null, true, true); } Note, that the second toCharArray-method is intended for parsing method signatures only and it fails with an IllegalArgumentException if no C_PARAM_START is found within the input. For length 0 this will invariable happen. Without changing the behavior the same could be achieved (in a less confusing way) by: int sigLength = signature.length; if (sigLength == 0) throw new IllegalArgumentException(); if (signature[0] == C_PARAM_START || signature[0] == C_GENERIC_START) { return toCharArray(signature, CharOperation.NO_CHAR, null, true, true); } If that's indeed the intended behavior I'd suggest to add to the docs that the input must not be an empty string/char[].
(In reply to comment #0) > If that's indeed the intended behavior I'd suggest to add to the docs that > the input must not be an empty string/char[]. This is a good suggestion. I missed it. Will be fixed for 3.6M5.
Created attachment 154253 [details] Proposed fix
Released for 3.6M5. Verification must be done by checking the javadoc.
Verified for 3.6M5 through code inspection.
Verified.