Bug 37200 - "Source->Generate Delegate Methods..." fails
Summary: "Source->Generate Delegate Methods..." fails
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 2.1   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.0 M1   Edit
Assignee: Olivier Thomann CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2003-05-04 08:17 EDT by box2419 CLA
Modified: 2003-07-18 07:50 EDT (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description box2419 CLA 2003-05-04 08:17:53 EDT
I defined a field for a class and then tried to generate delegate methods for 
the field. After I picked the methods to generate and hit "OK" an error 
message appeared which directed me to the log file:

!SESSION May 04, 2003 06:59:50.210 --------------------------------------------
-
java.version=1.4.2-beta
java.vendor=Sun Microsystems Inc.
BootLoader constants: OS=win32, ARCH=x86, WS=win32, NL=en_US
Command-line arguments: -os win32 -ws win32 -arch x86 -data C:\Documents and 
Settings\Assaf\.eclipse-workspace -install file:C:/Program Files/eclipse/
!ENTRY org.eclipse.jdt.ui 4 10001 May 04, 2003 06:59:50.210
!MESSAGE Internal Error
!STACK 0
java.lang.reflect.InvocationTargetException
	at org.eclipse.jface.operation.ModalContext.runInCurrentThread
(ModalContext.java:313)
	at org.eclipse.jface.operation.ModalContext.run(ModalContext.java:252)
	at org.eclipse.jface.dialogs.ProgressMonitorDialog.run
(ProgressMonitorDialog.java:357)
	at org.eclipse.jdt.ui.actions.AddDelegateMethodsAction.processResults
(AddDelegateMethodsAction.java:554)
	at org.eclipse.jdt.ui.actions.AddDelegateMethodsAction.showUI
(AddDelegateMethodsAction.java:365)
	at org.eclipse.jdt.ui.actions.AddDelegateMethodsAction.run
(AddDelegateMethodsAction.java:251)
	at org.eclipse.jdt.ui.actions.AddDelegateMethodsAction.run
(AddDelegateMethodsAction.java:282)
	at org.eclipse.jdt.ui.actions.SelectionDispatchAction.dispatchRun
(SelectionDispatchAction.java:193)
	at org.eclipse.jdt.ui.actions.SelectionDispatchAction.run
(SelectionDispatchAction.java:169)
	at org.eclipse.jface.action.Action.runWithEvent(Action.java:842)
	at 
org.eclipse.jface.action.ActionContributionItem.handleWidgetSelection
(ActionContributionItem.java:456)
	at org.eclipse.jface.action.ActionContributionItem.handleWidgetEvent
(ActionContributionItem.java:403)
	at org.eclipse.jface.action.ActionContributionItem.access$0
(ActionContributionItem.java:397)
	at 
org.eclipse.jface.action.ActionContributionItem$ActionListener.handleEvent
(ActionContributionItem.java:72)
	at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:81)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:840)
	at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:1838)
	at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:1545)
	at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:1402)
	at org.eclipse.ui.internal.Workbench.run(Workbench.java:1385)
	at org.eclipse.core.internal.boot.InternalBootLoader.run
(InternalBootLoader.java:845)
	at org.eclipse.core.boot.BootLoader.run(BootLoader.java:461)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.lang.reflect.Method.invoke(Unknown Source)
	at org.eclipse.core.launcher.Main.basicRun(Main.java:291)
	at org.eclipse.core.launcher.Main.run(Main.java:747)
	at org.eclipse.core.launcher.Main.main(Main.java:583)
Caused by: java.lang.NullPointerException
	at 
org.eclipse.jdt.internal.core.CreateElementInCUOperation.executeOperation
(CreateElementInCUOperation.java:140)
	at org.eclipse.jdt.internal.core.JavaModelOperation.execute
(JavaModelOperation.java:365)
	at org.eclipse.jdt.internal.core.JavaModelOperation.run
(JavaModelOperation.java:684)
	at org.eclipse.core.internal.resources.Workspace.run
(Workspace.java:1595)
	at org.eclipse.jdt.internal.core.JavaElement.runOperation
(JavaElement.java:543)
	at org.eclipse.jdt.internal.core.SourceType.createMethod
(SourceType.java:109)
	at org.eclipse.jdt.ui.actions.AddDelegateMethodsAction$ResultRunner.run
(AddDelegateMethodsAction.java:479)
	at org.eclipse.jdt.internal.core.BatchOperation.executeOperation
(BatchOperation.java:34)
	at org.eclipse.jdt.internal.core.JavaModelOperation.execute
(JavaModelOperation.java:365)
	at org.eclipse.jdt.internal.core.JavaModelOperation.run
(JavaModelOperation.java:684)
	at org.eclipse.core.internal.resources.Workspace.run
(Workspace.java:1595)
	at org.eclipse.jdt.core.JavaCore.run(JavaCore.java:2711)
	at org.eclipse.jdt.internal.ui.actions.WorkbenchRunnableAdapter.run
(WorkbenchRunnableAdapter.java:42)
	at org.eclipse.jface.operation.ModalContext.runInCurrentThread
(ModalContext.java:302)
	... 28 more
Comment 1 Olivier Thomann CLA 2003-05-05 13:50:26 EDT
Could you please attach your compilation unit source prior to the addition of
the getters/setters of your field? I need a reproducable test case.
Thanks.
Comment 2 box2419 CLA 2003-05-05 19:32:01 EDT
This seems to be easily reproducible. Just use the following:

public class Test {
    protected java.util.Map map;
}

... and try to generate delegate methods (not getters and setters) for 
the "map" field. Note that I am using JDK 1.4.2 beta.
Comment 3 Olivier Thomann CLA 2003-05-06 10:10:41 EDT
I tried the same test case without much success. I end up with:

import java.util.Collection;
import java.util.Map;
import java.util.Set;

public class Test {
    protected java.util.Map map;
	/**
	 * 
	 */
	public void clear() {
		map.clear();
	}

	/**
	 * @param key
	 * @return
	 */
	public boolean containsKey(Object key) {
		return map.containsKey(key);
	}

	/**
	 * @param value
	 * @return
	 */
	public boolean containsValue(Object value) {
		return map.containsValue(value);
	}

	/**
	 * @return
	 */
	public Set entrySet() {
		return map.entrySet();
	}

	/* (non-Javadoc)
	 * @see java.lang.Object#equals(java.lang.Object)
	 */
	public boolean equals(Object obj) {
		return map.equals(obj);
	}

	/**
	 * @param key
	 * @return
	 */
	public Object get(Object key) {
		return map.get(key);
	}

	/* (non-Javadoc)
	 * @see java.lang.Object#hashCode()
	 */
	public int hashCode() {
		return map.hashCode();
	}

	/**
	 * @return
	 */
	public boolean isEmpty() {
		return map.isEmpty();
	}

	/**
	 * @return
	 */
	public Set keySet() {
		return map.keySet();
	}

	/**
	 * @param key
	 * @param value
	 * @return
	 */
	public Object put(Object key, Object value) {
		return map.put(key, value);
	}

	/**
	 * @param t
	 */
	public void putAll(Map t) {
		map.putAll(t);
	}

	/**
	 * @param key
	 * @return
	 */
	public Object remove(Object key) {
		return map.remove(key);
	}

	/**
	 * @return
	 */
	public int size() {
		return map.size();
	}

	/* (non-Javadoc)
	 * @see java.lang.Object#toString()
	 */
	public String toString() {
		return map.toString();
	}

	/**
	 * @return
	 */
	public Collection values() {
		return map.values();
	}

}

And no errors.
Do you have an error in your class prior to generate delegate methods? Could you
please try with a new workspace from scratch? Do you have autobuild on?
You might have something wrong with your workspace. I need to understand what is
wrong.
Comment 4 box2419 CLA 2003-05-06 19:31:42 EDT
Got it! I created a brand new workspace and things worked just fine. I then 
went ahead and applied some of my non-default preferences to the new workspace 
and found the reason.

Simply go to Window->Preferences->Java->Code Generation->Code and Comments" 
and modify the pattern for Methods from:

/**
 * ${tags}
 */

to:

//

Once you have made this change on the new workspace you can reproduce the bug!
Comment 5 Olivier Thomann CLA 2003-05-07 10:43:36 EDT
A workaround is to add a line break after the '//' in the method comment. The
bug comes from the fact that the method comment is added in front of the
generated source and because there is no line break, the method header is
included in the line comment. So you end up trying to create a method with the
following source:
	//public void clear() {
	map.clear();
}
instead of:
//
public void clear() {
	map.clear();
}

I will changed the jdtcore operation to report a error in this case. The UI code
needs to be updated as well. I will enter another bug report for this against
JDT/UI.
Comment 6 Olivier Thomann CLA 2003-05-07 11:53:20 EDT
I will fix JDT/Core bug, but as long as this bug 37331 has not been fixed, your
test case will still fail.
Comment 7 Olivier Thomann CLA 2003-05-07 12:46:11 EDT
Fixed and released in HEAD stream.
Regression tests will be added shortly.
Comment 8 David Audel CLA 2003-07-18 07:50:20 EDT
Verified.