Skip to content

Commit ab4aa4d

Browse files
committed
Fix Debug Hover showing SuperClass Field's value in Subclass Field
This commit adds an additional computation for finding the subclass class field if superclass has same field as of subclass Fixes : #924
1 parent 5897f0e commit ab4aa4d

File tree

5 files changed

+94
-1
lines changed

5 files changed

+94
-1
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2026 IBM Corporation.
3+
*
4+
* This program and the accompanying materials
5+
* are made available under the terms of the Eclipse Public License 2.0
6+
* which accompanies this distribution, and is available at
7+
* https://www.eclipse.org/legal/epl-2.0/
8+
*
9+
* SPDX-License-Identifier: EPL-2.0
10+
*
11+
* Contributors:
12+
* IBM Corporation - initial API and implementation
13+
*******************************************************************************/
14+
public class SubClass extends SuperClass {
15+
private boolean fInitialized;
16+
17+
public SubClass() {
18+
fInitialized = false;
19+
System.out.println("SubClass constructor");
20+
}
21+
22+
public static void main(String[] args) {
23+
new SubClass();
24+
}
25+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2026 IBM Corporation.
3+
*
4+
* This program and the accompanying materials
5+
* are made available under the terms of the Eclipse Public License 2.0
6+
* which accompanies this distribution, and is available at
7+
* https://www.eclipse.org/legal/epl-2.0/
8+
*
9+
* SPDX-License-Identifier: EPL-2.0
10+
*
11+
* Contributors:
12+
* IBM Corporation - initial API and implementation
13+
*******************************************************************************/
14+
public class SuperClass {
15+
private boolean fInitialized = true;
16+
17+
public SuperClass() {
18+
19+
}
20+
}

org.eclipse.jdt.debug.tests/tests/org/eclipse/jdt/debug/tests/AbstractDebugTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -552,6 +552,8 @@ synchronized void assert18Project() {
552552
cfgs.add(createLaunchConfiguration(jp, "GH275"));
553553
cfgs.add(createLaunchConfiguration(jp, "LambdaTest"));
554554
cfgs.add(createLaunchConfiguration(jp, "InnerClassBug"));
555+
cfgs.add(createLaunchConfiguration(jp, "SuperClass"));
556+
cfgs.add(createLaunchConfiguration(jp, "SubClass"));
555557
loaded18 = true;
556558
waitForBuild();
557559
}

org.eclipse.jdt.debug.tests/tests/org/eclipse/jdt/debug/tests/ui/DebugHoverTests.java

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1559,4 +1559,39 @@ public void testHoverOnInnerClassConstructorVariables() throws Exception {
15591559
}
15601560
}
15611561

1562+
public void testResolveSameFieldsInSuperAndSub() throws Exception {
1563+
sync(() -> TestUtil.waitForJobs(getName(), 1000, 10000, ProcessConsole.class));
1564+
1565+
final String typeName = "SubClass";
1566+
final String expectedMethod = "<init>";
1567+
final int framesNumber = 2;
1568+
final int bpLine1 = 18;
1569+
1570+
IJavaBreakpoint bp1 = createLineBreakpoint(bpLine1, "", typeName + ".java", typeName);
1571+
bp1.setSuspendPolicy(IJavaBreakpoint.SUSPEND_THREAD);
1572+
IFile file = (IFile) bp1.getMarker().getResource();
1573+
assertEquals(typeName + ".java", file.getName());
1574+
1575+
IJavaThread thread = null;
1576+
try {
1577+
thread = launchToBreakpoint(typeName);
1578+
CompilationUnitEditor part = openEditorAndValidateStack(expectedMethod, framesNumber, file, thread);
1579+
1580+
JavaDebugHover hover = new JavaDebugHover();
1581+
hover.setEditor(part);
1582+
int offset = part.getViewer().getDocument().get().indexOf("fInitialized = ");
1583+
String variableName = "fInitialized";
1584+
IRegion region = new Region(offset, variableName.length());
1585+
String text = selectAndReveal(part, bpLine1, region);
1586+
assertEquals(variableName, text);
1587+
IVariable info = (IVariable) sync(() -> hover.getHoverInfo2(part.getViewer(), region));
1588+
assertNotNull(info);
1589+
assertEquals(variableName, info.getName());
1590+
assertEquals("false", info.getValue().getValueString());
1591+
} finally {
1592+
terminateAndRemove(thread);
1593+
removeAllBreakpoints();
1594+
}
1595+
}
1596+
15621597
}

org.eclipse.jdt.debug/model/org/eclipse/jdt/internal/debug/core/model/JDIObjectValue.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2000, 2015 IBM Corporation and others.
2+
* Copyright (c) 2000, 2026 IBM Corporation and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -277,6 +277,17 @@ public IJavaFieldVariable getField(final String name, final String declaringType
277277
field = fieldTmp;
278278
break;
279279
}
280+
List<Field> fieldList = ref.allFields(); // Possible sub class fields with same name as of super class
281+
fieldList.remove(fieldTmp);
282+
for (Field fieldCurrentTmp : fieldList) {
283+
if (name.equals(fieldCurrentTmp.name())) {
284+
String signatureCurrent = fieldCurrentTmp.declaringType().signature();
285+
if (declaringTypeSignature.equals(signatureCurrent)) {
286+
field = fieldCurrentTmp;
287+
break main;
288+
}
289+
}
290+
}
280291
// check if we are inside local type - Signature.createTypeSignature
281292
// can't create proper type name out of source field in JavaDebugHover
282293
// we get LDebugHoverTest$InnerClass2; instead of LDebugHoverTest$1InnerClass2;

0 commit comments

Comments
 (0)