JDK-8160024 : jdb returns invalid argument count if first parameter to Arrays.asList is null
  • Type: Bug
  • Component: core-svc
  • Sub-Component: debugger
  • Affected Version: 8u92,9
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2016-06-21
  • Updated: 2017-11-29
  • Resolved: 2016-11-08
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 8 JDK 9
8u152Fixed 9 b150Fixed
Description
@ 
On 8u92, jdb eval returns "Invalid argument count: expected 1, received 2"
with Arrays.asList(null, "a") though this line of code runs fine.
@ 
@ 

Comments
The suggested fix is: hg diff src/jdk.jdi/share/classes/com/sun/tools/jdi/MethodImpl.java diff -r 028d56ebb42a src/jdk.jdi/share/classes/com/sun/tools/jdi/MethodImpl.java --- a/src/jdk.jdi/share/classes/com/sun/tools/jdi/MethodImpl.java Thu Oct 13 09:02:13 2016 -0700 +++ b/src/jdk.jdi/share/classes/com/sun/tools/jdi/MethodImpl.java Tue Oct 18 09:24:31 2016 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1998, 2011, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1998, 2016, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -315,10 +315,11 @@ return; } Value nthArgValue = arguments.get(paramCount - 1); - if (nthArgValue == null) { + if (nthArgValue == null && argCount == paramCount) { + // The only one varargs parameter is null return; } - Type nthArgType = nthArgValue.type(); + Type nthArgType = (nthArgValue == null) ? null : nthArgValue.type(); if (nthArgType instanceof ArrayTypeImpl) { if (argCount == paramCount && ((ArrayTypeImpl)nthArgType).isAssignableTo(lastParamType)) {
18-10-2016

The root cause is in the JDI: src/jdk.jdi/share/classes/com/sun/tools/jdi/MethodImpl.java List<Value> validateAndPrepareArgumentsForInvoke(List<? extends Value> origArguments) throws ClassNotLoadedException, InvalidTypeException { . . . List<Value> arguments = new ArrayList<Value>(origArguments); The result of new ArrayList<Value>(origArguments) is different if the first origArguments element is null: arguments: [null, "Serg"] otherwise the result is: arguments: [instance of java.lang.Object[2] (id=558)] It seems, the difference comes from the method handleVarArgs().
14-10-2016