Home » Eclipse Projects » GEF » UpdateListener.firePainting(Rectangle, Map) causes NullPointerException
UpdateListener.firePainting(Rectangle, Map) causes NullPointerException [message #225387] |
Mon, 30 October 2006 18:50 ![Go to next message Go to next message](theme/Solstice/images/down.png) |
Del Myers![Friend of Eclipse Friend](/donate/web-api/friends_decorator.php?email=delmyers.cs%40gmail.com) Messages: 82 Registered: July 2009 |
Member |
|
|
I've already submitted a bug report as #162779, but I thought that it would be
good to post here as well, and check to see if anyone else has had similar problems.
I have an editpart viewer that listens for paint events in other editpart
viewers. So, my viewer adds and removes paint listeners from update managers
quite often. As a result, I believe that I found this bug in the UpdateManager
code. I think that it originates in the removeUpdateListener(UpdateListener) source:
public void removeUpdateListener(UpdateListener listener) {
if (listener == null)
throw new IllegalArgumentException();
for (int index = 0; index < listeners.length; index++)
if (listeners[index] == listener) {
int newSize = listeners.length - 1;
/****** BUG Here: newListeners[] is set to null when the new size==0 *****/
UpdateListener newListeners[] = null;
/*********************************************************** **************/
if (newSize != 0) {
newListeners = new UpdateListener[newSize];
System.arraycopy(listeners, 0, newListeners, 0, index);
System.arraycopy(listeners, index + 1, newListeners, index, newSize - index);
}
/*************** BUG here newListeners is null when newSize == 0 ************/
listeners = newListeners;
/*********************************************************** ****************/
return;
}
}
Then firePainting(Rectangle, Map) assumes that this.listeners will never be null:
protected void firePainting(Rectangle damage, Map dirtyRegions) {
UpdateListener localListeners[] = listeners;
for (int i = 0; i < localListeners.length; i++)
localListeners[i].notifyPainting(damage, dirtyRegions);
}
The bug, I believe, can be fixed by either setting the listeners to a size-0
array, or by checking for null.
Here is my stack trace:
3-0\13-0\13-2\00-193-1\03-0\12-0\1org.eclipse.swt.SWTExcepti on: Failed to
execute runnable (java.lang.NullPointerException)
at org.eclipse.swt.SWT.error(SWT.java:3374)
at org.eclipse.swt.SWT.error(SWT.java:3297)
at org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Synchr onizer.java:126)
at org.eclipse.swt.widgets.Display.runAsyncMessages(Display.jav a:3325)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java :2971)
at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.jav a:1914)
at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:1878)
at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Work bench.java:419)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.j ava:149)
at zestrcp.Application.run(Application.java:18)
at
org.eclipse.core.internal.runtime.PlatformActivator$1.run(Pl atformActivator.java:78)
at
org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher .runApplication(EclipseAppLauncher.java:92)
at
org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher .start(EclipseAppLauncher.java:68)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseS tarter.java:400)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseS tarter.java:177)
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.invokeFramework(Main.java:336 )
at org.eclipse.core.launcher.Main.basicRun(Main.java:280)
at org.eclipse.core.launcher.Main.run(Main.java:977)
at org.eclipse.core.launcher.Main.main(Main.java:952)
Caused by: java.lang.NullPointerException
at org.eclipse.draw2d.UpdateManager.firePainting(UpdateManager. java:113)
at
org.eclipse.draw2d.DeferredUpdateManager.repairDamage(Deferr edUpdateManager.java:267)
at
org.eclipse.draw2d.DeferredUpdateManager.performUpdate(Defer redUpdateManager.java:167)
at
org.eclipse.draw2d.DeferredUpdateManager$UpdateRequest.run(D eferredUpdateManager.java:46)
at org.eclipse.swt.widgets.RunnableLock.run(RunnableLock.java:3 5)
at org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Synchr onizer.java:123)
... 20 more
|
|
|
Re: UpdateListener.firePainting(Rectangle, Map) causes NullPointerException [message #225441 is a reply to message #225387] |
Tue, 31 October 2006 03:55 ![Go to previous message Go to previous message](theme/Solstice/images/up.png) ![Go to next message Go to next message](theme/Solstice/images/down.png) |
Xiang Qinxian![Friend of Eclipse Friend](/donate/web-api/friends_decorator.php?email=fyaoxy%40gmail.com) Messages: 119 Registered: July 2009 |
Senior Member |
|
|
Hi,
I agree with you.
Regards,
Qinxian
在 2006-10-30一的 10:50 -0800,Del Myers写道:
> I've already submitted a bug report as #162779, but I thought that it would be
> good to post here as well, and check to see if anyone else has had similar problems.
>
> I have an editpart viewer that listens for paint events in other editpart
> viewers. So, my viewer adds and removes paint listeners from update managers
> quite often. As a result, I believe that I found this bug in the UpdateManager
> code. I think that it originates in the removeUpdateListener(UpdateListener) source:
>
>
> public void removeUpdateListener(UpdateListener listener) {
> if (listener == null)
> throw new IllegalArgumentException();
> for (int index = 0; index < listeners.length; index++)
> if (listeners[index] == listener) {
> int newSize = listeners.length - 1;
> /****** BUG Here: newListeners[] is set to null when the new size==0 *****/
> UpdateListener newListeners[] = null;
> /*********************************************************** **************/
> if (newSize != 0) {
> newListeners = new UpdateListener[newSize];
> System.arraycopy(listeners, 0, newListeners, 0, index);
> System.arraycopy(listeners, index + 1, newListeners, index, newSize - index);
> }
> /*************** BUG here newListeners is null when newSize == 0 ************/
> listeners = newListeners;
> /*********************************************************** ****************/
> return;
> }
> }
>
> Then firePainting(Rectangle, Map) assumes that this.listeners will never be null:
>
> protected void firePainting(Rectangle damage, Map dirtyRegions) {
> UpdateListener localListeners[] = listeners;
> for (int i = 0; i < localListeners.length; i++)
> localListeners[i].notifyPainting(damage, dirtyRegions);
> }
>
>
> The bug, I believe, can be fixed by either setting the listeners to a size-0
> array, or by checking for null.
>
> Here is my stack trace:
>
>
>
> 3-0\13-0\13-2\00-193-1\03-0\12-0\1org.eclipse.swt.SWTExcepti on: Failed to
> execute runnable (java.lang.NullPointerException)
> at org.eclipse.swt.SWT.error(SWT.java:3374)
> at org.eclipse.swt.SWT.error(SWT.java:3297)
> at org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Synchr onizer.java:126)
> at org.eclipse.swt.widgets.Display.runAsyncMessages(Display.jav a:3325)
> at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java :2971)
> at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.jav a:1914)
> at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:1878)
> at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Work bench.java:419)
> at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.j ava:149)
> at zestrcp.Application.run(Application.java:18)
> at
> org.eclipse.core.internal.runtime.PlatformActivator$1.run(Pl atformActivator.java:78)
> at
> org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher .runApplication(EclipseAppLauncher.java:92)
> at
> org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher .start(EclipseAppLauncher.java:68)
> at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseS tarter.java:400)
> at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseS tarter.java:177)
> 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.invokeFramework(Main.java:336 )
> at org.eclipse.core.launcher.Main.basicRun(Main.java:280)
> at org.eclipse.core.launcher.Main.run(Main.java:977)
> at org.eclipse.core.launcher.Main.main(Main.java:952)
> Caused by: java.lang.NullPointerException
> at org.eclipse.draw2d.UpdateManager.firePainting(UpdateManager. java:113)
> at
> org.eclipse.draw2d.DeferredUpdateManager.repairDamage(Deferr edUpdateManager.java:267)
> at
> org.eclipse.draw2d.DeferredUpdateManager.performUpdate(Defer redUpdateManager.java:167)
> at
> org.eclipse.draw2d.DeferredUpdateManager$UpdateRequest.run(D eferredUpdateManager.java:46)
> at org.eclipse.swt.widgets.RunnableLock.run(RunnableLock.java:3 5)
> at org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Synchr onizer.java:123)
> ... 20 more
|
|
|
Re: UpdateListener.firePainting(Rectangle, Map) causesNullPointerException [message #225636 is a reply to message #225441] |
Wed, 01 November 2006 05:55 ![Go to previous message Go to previous message](theme/Solstice/images/up.png) ![Go to next message Go to next message](theme/Solstice/images/down.png) |
Dazhen Gao![Friend of Eclipse Friend](/donate/web-api/friends_decorator.php?email=dgao%40actuate.com) Messages: 21 Registered: July 2009 |
Junior Member |
|
|
Why throw the nullpoint exception, if you add a new updatelistener and
remove it, it don't throw the exception.Because FigureCavas adda a listener
already, so the listen size can't ne zero.
But the code maybe wrong, should be
public void removeUpdateListener(UpdateListener listener) {
if (listener == null)
throw new IllegalArgumentException();
for (int index = 0; index < listeners.length; index++)
if (listeners[index] == listener) {
int newSize = listeners.length - 1;
//declare should be here
newListeners = new UpdateListener[newSize];
if (newSize != 0) {
System.arraycopy(listeners, 0, newListeners, 0, index);
System.arraycopy(listeners, index + 1, newListeners, index, newSize -
index);
}
listeners = newListeners;
return;
}
}
"Xiang Qinxian" <fyaoxy@gmail.com> wrote in message
news:1162266944.479.42.camel@qinxian.xiang...
Hi,
I agree with you.
Regards,
Qinxian
|
|
|
Re: UpdateListener.firePainting(Rectangle, Map) causesNullPointerException [message #225686 is a reply to message #225636] |
Wed, 01 November 2006 17:19 ![Go to previous message Go to previous message](theme/Solstice/images/up.png) |
Del Myers![Friend of Eclipse Friend](/donate/web-api/friends_decorator.php?email=delmyers.cs%40gmail.com) Messages: 82 Registered: July 2009 |
Member |
|
|
Well, none of my code removes the FigureCanvas listener, so obviously something
is going wrong. The fact of the matter is I get a NPE.
Del
gao wrote:
> Why throw the nullpoint exception, if you add a new updatelistener and
> remove it, it don't throw the exception.Because FigureCavas adda a listener
> already, so the listen size can't ne zero.
> But the code maybe wrong, should be
>
> public void removeUpdateListener(UpdateListener listener) {
> if (listener == null)
> throw new IllegalArgumentException();
> for (int index = 0; index < listeners.length; index++)
> if (listeners[index] == listener) {
> int newSize = listeners.length - 1;
> //declare should be here
> newListeners = new UpdateListener[newSize];
> if (newSize != 0) {
> System.arraycopy(listeners, 0, newListeners, 0, index);
> System.arraycopy(listeners, index + 1, newListeners, index, newSize -
> index);
> }
> listeners = newListeners;
> return;
> }
> }
> "Xiang Qinxian" <fyaoxy@gmail.com> wrote in message
> news:1162266944.479.42.camel@qinxian.xiang...
> Hi,
> I agree with you.
>
> Regards,
>
> Qinxian
> ÔÚ 2006-10-30Ò»µÄ 10:50 -0800£¬Del MyersдµÀ£º
>> I've already submitted a bug report as #162779, but I thought that it
>> would be
>> good to post here as well, and check to see if anyone else has had similar
>> problems.
>>
>> I have an editpart viewer that listens for paint events in other editpart
>> viewers. So, my viewer adds and removes paint listeners from update
>> managers
>> quite often. As a result, I believe that I found this bug in the
>> UpdateManager
>> code. I think that it originates in the
>> removeUpdateListener(UpdateListener) source:
>>
>>
>> public void removeUpdateListener(UpdateListener listener) {
>> if (listener == null)
>> throw new IllegalArgumentException();
>> for (int index = 0; index < listeners.length; index++)
>> if (listeners[index] == listener) {
>> int newSize = listeners.length - 1;
>> /****** BUG Here: newListeners[] is set to null when the new size==0
>> *****/
>> UpdateListener newListeners[] = null;
>> /*********************************************************** **************/
>> if (newSize != 0) {
>> newListeners = new UpdateListener[newSize];
>> System.arraycopy(listeners, 0, newListeners, 0, index);
>> System.arraycopy(listeners, index + 1, newListeners, index, newSize -
>> index);
>> }
>> /*************** BUG here newListeners is null when newSize == 0
>> ************/
>> listeners = newListeners;
>> /*********************************************************** ****************/
>> return;
>> }
>> }
>>
>> Then firePainting(Rectangle, Map) assumes that this.listeners will never
>> be null:
>>
>> protected void firePainting(Rectangle damage, Map dirtyRegions) {
>> UpdateListener localListeners[] = listeners;
>> for (int i = 0; i < localListeners.length; i++)
>> localListeners[i].notifyPainting(damage, dirtyRegions);
>> }
>>
>>
>> The bug, I believe, can be fixed by either setting the listeners to a
>> size-0
>> array, or by checking for null.
>>
>> Here is my stack trace:
>>
>>
>>
>> 3-0\13-0\13-2\00-193-1\03-0\12-0\1org.eclipse.swt.SWTExcepti on: Failed to
>> execute runnable (java.lang.NullPointerException)
>> at org.eclipse.swt.SWT.error(SWT.java:3374)
>> at org.eclipse.swt.SWT.error(SWT.java:3297)
>> at
>> org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Synchr onizer.java:126)
>> at org.eclipse.swt.widgets.Display.runAsyncMessages(Display.jav a:3325)
>> at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java :2971)
>> at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.jav a:1914)
>> at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:1878)
>> at
>> org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Work bench.java:419)
>> at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.j ava:149)
>> at zestrcp.Application.run(Application.java:18)
>> at
>> org.eclipse.core.internal.runtime.PlatformActivator$1.run(Pl atformActivator.java:78)
>> at
>> org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher .runApplication(EclipseAppLauncher.java:92)
>> at
>> org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher .start(EclipseAppLauncher.java:68)
>> at
>> org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseS tarter.java:400)
>> at
>> org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseS tarter.java:177)
>> 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.invokeFramework(Main.java:336 )
>> at org.eclipse.core.launcher.Main.basicRun(Main.java:280)
>> at org.eclipse.core.launcher.Main.run(Main.java:977)
>> at org.eclipse.core.launcher.Main.main(Main.java:952)
>> Caused by: java.lang.NullPointerException
>> at org.eclipse.draw2d.UpdateManager.firePainting(UpdateManager. java:113)
>> at
>> org.eclipse.draw2d.DeferredUpdateManager.repairDamage(Deferr edUpdateManager.java:267)
>> at
>> org.eclipse.draw2d.DeferredUpdateManager.performUpdate(Defer redUpdateManager.java:167)
>> at
>> org.eclipse.draw2d.DeferredUpdateManager$UpdateRequest.run(D eferredUpdateManager.java:46)
>> at org.eclipse.swt.widgets.RunnableLock.run(RunnableLock.java:3 5)
>> at
>> org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Synchr onizer.java:123)
>> ... 20 more
>
>
|
|
|
Goto Forum:
Current Time: Fri Apr 26 14:49:14 GMT 2024
Powered by FUDForum. Page generated in 0.04323 seconds
|