JDK-8243651 : java for-each loop should handle nulls cleanly.
  • Type: Enhancement
  • Component: specification
  • Sub-Component: language
  • Affected Version: 15
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_10
  • CPU: x86_64
  • Submitted: 2020-04-23
  • Updated: 2024-12-03
  • Resolved: 2020-04-27
Related Reports
Duplicate :  
Relates :  
Description
A DESCRIPTION OF THE PROBLEM :
java for-each loop throws a NullPointerException when a null collection is passed in.  Instead, it should act like it does for an empty collection and just exit the loop cleanly.  This would reduce a lot of boilerplate code that either has to check for null values, use Optionals, or the use of third party software (eg apache.commons).  



Comments
This is a duplicate of https://bugs.openjdk.java.net/browse/JDK-6341875 hence, closing the issue.
27-04-2020