Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions org.eclipse.jdt.debug.tests/java8/InnerClassBug.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*******************************************************************************
* Copyright (c) 2026 IBM Corporation.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
public class InnerClassBug {

public static void main(String[] args) {
InnerClassBug a = new InnerClassBug();
T t = a.new T(4);
System.out.println(t.x);
}

private class T {
final int x;
private T(int x1) {
this.x = x1;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,7 @@ synchronized void assert18Project() {
cfgs.add(createLaunchConfiguration(jp, "LambdaBreakpoints1"));
cfgs.add(createLaunchConfiguration(jp, "GH275"));
cfgs.add(createLaunchConfiguration(jp, "LambdaTest"));
cfgs.add(createLaunchConfiguration(jp, "InnerClassBug"));
loaded18 = true;
waitForBuild();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2017, 2024 Andrey Loskutov and others.
* Copyright (c) 2017, 2026 Andrey Loskutov and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
Expand Down Expand Up @@ -1527,4 +1527,36 @@ public void testResolveIn2Lambdas() throws Exception {
}
}

public void testHoverOnInnerClassConstructorVariables() throws Exception {
sync(() -> TestUtil.waitForJobs(getName(), 1000, 10000, ProcessConsole.class));
final String typeName = "InnerClassBug";
final String expectedMethod = "<init>";
final int frameNumber = 3;
final int bpLine = 25;
IJavaBreakpoint bp = createLineBreakpoint(bpLine, "", typeName + ".java", typeName);
bp.setSuspendPolicy(IJavaBreakpoint.SUSPEND_THREAD);
IFile file = (IFile) bp.getMarker().getResource();
assertEquals(typeName + ".java", file.getName());
IJavaThread thread = null;
try {
thread = launchToBreakpoint(typeName);
CompilationUnitEditor part = openEditorAndValidateStack(expectedMethod, frameNumber, file, thread);
JavaDebugHover hover = new JavaDebugHover();
hover.setEditor(part);
String variableName = "x1";
int offset = part.getViewer().getDocument().get().indexOf("this.x = x1") + " this.x =".length();
IRegion region = new Region(offset, variableName.length());
String text = selectAndReveal(part, bpLine, region);
assertEquals(variableName, text);
IVariable info = (IVariable) sync(() -> hover.getHoverInfo2(part.getViewer(), region));

assertNotNull(info);
assertEquals(variableName, info.getName());
assertEquals("4", info.getValue().getValueString());
} finally {
terminateAndRemove(thread);
removeAllBreakpoints();
}
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2020 IBM Corporation and others.
* Copyright (c) 2000, 2026 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
Expand Down Expand Up @@ -448,7 +448,9 @@ public Object getHoverInfo2(ITextViewer textViewer, IRegion hoverRegion) {
}
else { // Finding variables in anonymous class
int index = frame.getDeclaringTypeName().indexOf('$');
if (index > 0) {
if (method.isConstructor() && index > 0) {
equal = true;
} else if (index > 0) {
String name = frame.getDeclaringTypeName().substring(index + 1);
try {
Integer.getInteger(name);
Expand Down
Loading