Bug 350745 - Varargs are not evaluated correctly when no arguments are given
Summary: Varargs are not evaluated correctly when no arguments are given
Status: ASSIGNED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Debug (show other bugs)
Version: 3.7   Edit
Hardware: PC Windows 7
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: JDT-Debug-Inbox CLA
QA Contact:
URL:
Whiteboard: stalebug
Keywords: helpwanted
Depends on:
Blocks:
 
Reported: 2011-06-29 16:02 EDT by Michael Rennie CLA
Modified: 2023-09-02 16:27 EDT (History)
3 users (show)

See Also:


Attachments
partial patch (4.16 KB, patch)
2011-06-29 16:59 EDT, Michael Rennie CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Michael Rennie CLA 2011-06-29 16:02:22 EDT
Using the following snippet as a condition for a breakpoint, you get an exception when the breakpoint is hit "java.lang.IllegalArgumentException: Number of arguments does not match"

MethodHandles.Lookup lookup = MethodHandles.lookup();
MethodType type = MethodType.methodType(boolean.class);
MethodHandle handle = lookup.findStatic(J7.class, "bool", type);
boolean value = (Boolean)handle.invoke();
System.out.println("invoked: "+value);

If I make the snippet simpler by calling my own varargs method:

void varargs(Object... args) {
  System.out.println("called varargs");
}

as a condition:

varargs();
return true;

I get the following exception:

java.lang.ArrayIndexOutOfBoundsException: -1
	at java.util.ArrayList.elementData(ArrayList.java:371)
	at java.util.ArrayList.get(ArrayList.java:384)
	at org.eclipse.jdt.core.dom.ASTNode$NodeList.get(ASTNode.java:1225)
	at org.eclipse.jdt.internal.debug.eval.ast.engine.ASTInstructionCompiler.pushMethodArguments(ASTInstructionCompiler.java:2783)
	at org.eclipse.jdt.internal.debug.eval.ast.engine.ASTInstructionCompiler.visit(ASTInstructionCompiler.java:2765)
	at org.eclipse.jdt.core.dom.MethodInvocation.accept0(MethodInvocation.java:237)
	at org.eclipse.jdt.core.dom.ASTNode.accept(ASTNode.java:2518)
	at org.eclipse.jdt.core.dom.ASTNode.acceptChild(ASTNode.java:2566)
	at org.eclipse.jdt.core.dom.ExpressionStatement.accept0(ExpressionStatement.java:144)
	at org.eclipse.jdt.core.dom.ASTNode.accept(ASTNode.java:2518)
	at org.eclipse.jdt.core.dom.ASTNode.acceptChildren(ASTNode.java:2589)
	at org.eclipse.jdt.core.dom.Block.accept0(Block.java:136)
	at org.eclipse.jdt.core.dom.ASTNode.accept(ASTNode.java:2518)
	at org.eclipse.jdt.core.dom.ASTNode.acceptChild(ASTNode.java:2566)
	at org.eclipse.jdt.core.dom.MethodDeclaration.accept0(MethodDeclaration.java:504)
	at org.eclipse.jdt.core.dom.ASTNode.accept(ASTNode.java:2518)
	at org.eclipse.jdt.core.dom.ASTNode.acceptChildren(ASTNode.java:2589)
	at org.eclipse.jdt.core.dom.TypeDeclaration.accept0(TypeDeclaration.java:484)
	at org.eclipse.jdt.core.dom.ASTNode.accept(ASTNode.java:2518)
	at org.eclipse.jdt.core.dom.ASTNode.acceptChildren(ASTNode.java:2589)
	at org.eclipse.jdt.core.dom.CompilationUnit.accept0(CompilationUnit.java:219)
	at org.eclipse.jdt.core.dom.ASTNode.accept(ASTNode.java:2518)
	at org.eclipse.jdt.internal.debug.eval.ast.engine.ASTEvaluationEngine.createExpressionFromAST(ASTEvaluationEngine.java:448)
	at org.eclipse.jdt.internal.debug.eval.ast.engine.ASTEvaluationEngine.getCompiledExpression(ASTEvaluationEngine.java:267)
	at org.eclipse.jdt.internal.debug.core.breakpoints.ConditionalBreakpointHandler.breakpointHit(ConditionalBreakpointHandler.java:198)
	at org.eclipse.jdt.internal.debug.core.model.JDIThread.handleSuspendForBreakpoint(JDIThread.java:1122)
	at org.eclipse.jdt.internal.debug.core.breakpoints.JavaBreakpoint.suspend(JavaBreakpoint.java:363)
	at org.eclipse.jdt.internal.debug.core.breakpoints.JavaBreakpoint.handleBreakpointEvent(JavaBreakpoint.java:351)
	at org.eclipse.jdt.internal.debug.core.breakpoints.JavaBreakpoint.handleEvent(JavaBreakpoint.java:288)
	at org.eclipse.jdt.internal.debug.core.EventDispatcher.dispatch(EventDispatcher.java:187)
	at org.eclipse.jdt.internal.debug.core.EventDispatcher.access$0(EventDispatcher.java:104)
	at org.eclipse.jdt.internal.debug.core.EventDispatcher$1.run(EventDispatcher.java:248)
	at org.eclipse.core.internal.jobs.Worker.run(Worker.java:54)
Comment 1 Michael Rennie CLA 2011-06-29 16:59:16 EDT
Created attachment 198863 [details]
partial patch

This patch fixes up the simple varargs case for the ArrayIndexOutOfBoundsException - we did not properly consider that varargs are '0 or more', so in the case of 0 arguments being passed in we tried to look up argument '-1'.
Comment 2 Michael Rennie CLA 2011-07-05 11:48:10 EDT
Tagging this for 3.8. After digging into the JDI / eval code I found this to be a problem with our handling of varargs in general and not an issue with Java 7.

Using the snippet + steps from comment #0 will produce the same exceptions / warnings using 1.5 and 1.6 VMs.
Comment 3 Dani Megert CLA 2011-09-14 04:17:13 EDT
Still planned for M2?
Comment 4 Michael Rennie CLA 2011-09-14 10:11:50 EDT
(In reply to comment #3)
> Still planned for M2?

No, the patch is only a partial solution. Moving to M3
Comment 5 Eclipse Genie CLA 2019-09-18 12:59:36 EDT
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.
Comment 6 Sarika Sinha CLA 2019-09-20 02:07:06 EDT
Nothing has changed.

Anyone interested in working on the partial patch?
Comment 7 Eclipse Genie CLA 2021-09-11 05:55:58 EDT
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.
Comment 8 Eclipse Genie CLA 2023-09-02 16:27:00 EDT
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.