-
Type:
Enhancement
-
Status: Closed
-
Priority:
P4
-
Resolution: Won't Fix
-
Affects Version/s: 14
-
Fix Version/s: None
-
Component/s: specification
-
Subcomponent:
A DESCRIPTION OF THE PROBLEM :
Using a for-each loop over an array is a nasty business :-) that requires an explicit null-check before entering the loop. Suggestion: allow the for-each loop/iterator to detect a null array, and execute 0 times w/o throwing an NPE. E.g.
String [] none = null;
for (String some: none) System.err.println(some);
would execute 0 times, and NOT throw an NPE.
The only downside to this that I can see is it MIGHT break code that (for poor design reasons) explicitly catches and checks for this case, and does something else (besides executing the loop 0 times). Arrays are passe', to be sure, and doing null-safe List's or Collection's in for-each loops are trivial. But arrays are a pain, and much legacy code (e.g. Castor XML->Java code generators) still produce arrays.
Using a for-each loop over an array is a nasty business :-) that requires an explicit null-check before entering the loop. Suggestion: allow the for-each loop/iterator to detect a null array, and execute 0 times w/o throwing an NPE. E.g.
String [] none = null;
for (String some: none) System.err.println(some);
would execute 0 times, and NOT throw an NPE.
The only downside to this that I can see is it MIGHT break code that (for poor design reasons) explicitly catches and checks for this case, and does something else (besides executing the loop 0 times). Arrays are passe', to be sure, and doing null-safe List's or Collection's in for-each loops are trivial. But arrays are a pain, and much legacy code (e.g. Castor XML->Java code generators) still produce arrays.