JDK-8151738 : MethodHandles.countedLoop(MH, MH, MH), body = null leads to NPE instead of IAE
  • Type: Sub-task
  • Component: core-libs
  • Sub-Component: java.lang.invoke
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2016-03-11
  • Updated: 2016-04-20
  • Resolved: 2016-03-21
Related Reports
Relates :  
Relates :  
Description
According to MethodHandles.countedLoop(MH, MH, MH) passing body = null should lead to IllegalArgumentException. 

Actual result is NullPointerException.
Exception in thread "main" java.lang.NullPointerException
	at java.lang.invoke.MethodHandles.dropArguments(MethodHandles.java:2526)
	at java.lang.invoke.MethodHandles.dropArguments(MethodHandles.java:2601)
	at java.lang.invoke.MethodHandles.countedLoop(MethodHandles.java:3767)
	at java.lang.invoke.MethodHandles.countedLoop(MethodHandles.java:3697)
	at CountedLoopTest1.main(CountedLoopTest1.java:11)


Was found on jdk9b107/jdk9b108, tests are under development. 
tck_red label will be added after tests completion.

Example is attached.

The same situation is in MethodHandles.countedLoop(MH, MH, MH, MH) 

Comments
Addressed internally; fix will be pushed with JDK-8151179.
21-03-2016

JDK-8151026 is very similar. However, fixing this issue requires a small correction in the countedLoop implementation to avoid passing a null body to dropArguments. It should be converted to a matching zeroHandle. Alternatively, the body argument can be passed through to the MHs.loop combinator invocation to let it handle the null body.
21-03-2016

A null body argument should be allowed to express an empty loop.
21-03-2016