Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 322100

Summary: [breakpoints] Cannot add breakpoints to anonymous inner class.
Product: [Eclipse Project] JDT Reporter: Matthew Goodson <matthew>
Component: DebugAssignee: JDT-Debug-Inbox <jdt-debug-inbox>
Status: CLOSED WONTFIX QA Contact:
Severity: normal    
Priority: P3 CC: markus.kell.r, Michael_Rennie, Olivier_Thomann, remy.suen
Version: 3.5.2   
Target Milestone: ---   
Hardware: PC   
OS: Linux   
Whiteboard: stalebug

Description Matthew Goodson CLA 2010-08-08 23:08:07 EDT
Build Identifier: 20100218-1602

I cannot add a breakpoint to the subclass of the AbstractReadOnlyModel in the code supplied. Also ctrl + space pop-ups will not show. However if I remove the subclass of the NonCachingImage then breakpoints and pop-ups work!?
Seems pretty random to me?
Thanks

Reproducible: Always

Steps to Reproduce:
final NonCachingImage image = new NonCachingImage("vehicleImage",
				new AbstractReadOnlyModel<Object>() {

			private static final long serialVersionUID = 1L;

			@Override
			public Object getObject() {
				try {
					VehicleDetachableModel vehicleModel = (VehicleDetachableModel)getParent().getDefaultModel();
					Vehicle vehicle = vehicleModel.getObject();
					
					Image iconImage;
					if (vehicle.getKey() == null) {
						iconImage = vehicle.getFullImage();
					} else {
						iconImage = vehicleModel.getSelectedVehicleWithImage().getFullImage();
					}
					byte[] byteArray = iconImage.getImage();
					return Utility.convertByteArrayToImageResourc(byteArray);
				} catch (Exception e) {
					return new ResourceReference(LogbookPage.class, "assets/img/forms/vehicleDefaultImage.jpg");
				}
			}
		}) {

			private static final long serialVersionUID = 1L;

			@Override
			protected void onAfterRender() {
				setImageResourceReference(null);
				super.onAfterRender();
			}
			
		};
Comment 1 Michael Rennie CLA 2010-08-09 11:46:18 EDT
I reproduced some weird breakpoint behavior here. If I try to set a breakpoint (margin toggle or keybinding) anywhere in the the new AbstractReadOnlyModel<Object> {...} declaration I only get a class load breakpoint on the final NonCachingImage image = .... line.

Matthew is this what you are seeing as well?

It feels to me like we should be able to set the correct kinds of breakpoints.
Comment 2 Michael Rennie CLA 2010-08-09 11:49:56 EDT
Also to note, if you try to remove the class load breakpoint you get a line breakpoint created instead of removing the class load breakpoint. The only way to remove the class load breakpoint is to try to add a breakpoint in the AbstractReadOnlyModel<Object>() {...} declaration again.

Here is an updated snippet for testing (removes compilation problems from the snippet in comment #0)

package snippet;

import java.awt.Image;

public class NonCachingImage {
	public NonCachingImage(String string, AbstractReadOnlyModel<Object> model) {}
	protected void onAfterRender() {}
	final NonCachingImage image = new NonCachingImage("vehicleImage", new AbstractReadOnlyModel<Object>() {
	            private static final long serialVersionUID = 1L;
	            @Override
	            public Object getObject() {
	                try {
	                    VehicleDetachableModel vehicleModel = ((VehicleDetachableModel)getParent()).getDefaultModel();
	                    Vehicle vehicle = (Vehicle) vehicleModel.getObject();
	                    Image iconImage;
	                    if (vehicle.getKey() == null) {
	                        iconImage = vehicle.getFullImage();
	                    } else {
	                        iconImage =	vehicleModel.getSelectedVehicleWithImage().getFullImage();
	                    }
	                    return null;
	                } catch (Exception e) {
	                }
	                return null;
	            }
	        }) {
	            private static final long serialVersionUID = 1L;
	            @Override
	            protected void onAfterRender() {
	                setImageResourceReference(null);
	                super.onAfterRender();
	            }
	        };

	protected void setImageResourceReference(Object object) {}
}
class AbstractReadOnlyModel<T> {
	public Object getObject() {return null;}
	public Object getParent() {return null;}
	VehicleDetachableModel getDefaultModel() {return null;}
}
class VehicleDetachableModel {
	public Object getObject() {return null;}
	public Vehicle getSelectedVehicleWithImage() {
		return null;
	}
	VehicleDetachableModel getDefaultModel() {return null;}
}
class Vehicle {
	Image getFullImage() {return null;}
	public Object getKey() {return null;}
}
Comment 3 Michael Rennie CLA 2010-08-09 12:10:38 EDT
heres a more compact snippet that demonstrates the problem I mentioned. 

public class MyString {
 public MyString(Object o) {}
 final MyString string = new MyString(new Object() {
  public boolean equals(Object o) {return false;}
 }) {
  public boolean equals(Object o) {return false;}
 };
}

Stepping through our code the call to ITypeRoot.getElementAt(offset) is returning the anonymous class declaration 'new Object() {...}' (line 3) as the smallest enclosing element even when you try to toggle a breakpoint on line 4.
Comment 4 Eclipse Genie CLA 2020-03-28 12:41:25 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. As such, we're closing this bug.

If you have further information on the current state of the bug, please add it and reopen this bug. 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.