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

Bug 283408

Summary: NullPointerException when calling Shape constructor thru Polygon default constructor
Product: [Tools] GEF Reporter: Jose M Beleta <jose>
Component: GEF-Legacy Draw2dAssignee: Marc Gobeil <mgobeil>
Status: RESOLVED FIXED QA Contact:
Severity: critical    
Priority: P3 CC: ahunter.eclipse, mgobeil
Version: 3.5   
Target Milestone: 3.5.0 (Galileo SR2)   
Hardware: PC   
OS: Windows Vista   
Whiteboard:
Attachments:
Description Flags
proposed patch
none
revised patch none

Description Jose M Beleta CLA 2009-07-14 08:49:36 EDT
Build ID: 20090621-0832

Steps To Reproduce:

1.Subclass Polygon
2.Call a constructor of your class
3.You get NullPointerException in Shape.getLineWidthFloat because lineAttributes is null.

More information:

The problem seems that in Shape constructor setOpaque is called before initializing lineAttributes;

Here is the stack:

Thread [main] (Suspended (exception NullPointerException))	
	PolygonFigure(Shape).getLineWidthFloat() line: 298	
	PolygonFigure(Polyline).getBounds() line: 67	
	PolygonFigure(Figure).repaint() line: 1328	
	PolygonFigure(Polyline).repaint() line: 141	
	PolygonFigure(Figure).setOpaque(boolean) line: 1579	
	PolygonFigure(Shape).<init>() line: 59	
	PolygonFigure(AbstractPointListShape).<init>() line: 23	
	PolygonFigure(Polyline).<init>() line: 28	
	PolygonFigure(Polygon).<init>() line: 23	
	PolygonFigure.<init>(PointList) line: 42	
...
Comment 1 Marc Gobeil CLA 2009-07-14 11:31:27 EDT
Created attachment 141535 [details]
proposed patch
Comment 2 Marc Gobeil CLA 2009-07-15 17:19:37 EDT
comitted to HEAD and R3_5_maintenance
Comment 3 Jose M Beleta CLA 2009-07-16 13:07:53 EDT
The proposed patch does not work because it throws the NullPointerException too, now in Polyline.getBounds().

The problem happens because a repaint is done in the shape constructor. The repaint() is called by setOpaque(). setOpaque() cannot be called in the Shape constructor.

Perhaps you should build some tests that include PolyLines.

Here is the new stack:

Thread [main] (Suspended (exception NullPointerException))	
	PolygonFigure(Polyline).getBounds() line: 69	
	PolygonFigure(Figure).repaint() line: 1328	
	PolygonFigure(Polyline).repaint() line: 141	
	PolygonFigure(Figure).setOpaque(boolean) line: 1579	
	PolygonFigure(Shape).<init>() line: 73	
	PolygonFigure(AbstractPointListShape).<init>() line: 23	
	PolygonFigure(Polyline).<init>() line: 28	
	PolygonFigure(Polygon).<init>() line: 23	
	PolygonFigure.<init>(PointList) line: 42	
...
Comment 4 Marc Gobeil CLA 2009-07-22 17:20:37 EDT
Created attachment 142325 [details]
revised patch

Sorry about that.  As discussed in bug 267397, setOpaque()'s functionality is being ignored by Shape anyway, so it's safe to simply remove it from the constructor.

Seems fine on my end, does it work for you?
Comment 5 Anthony Hunter CLA 2009-08-12 15:56:34 EDT
(In reply to comment #4)
> Seems fine on my end, does it work for you?

Jose? Does this work for you? 

Comment 6 Jose M Beleta CLA 2009-11-25 09:05:07 EST
(In reply to comment #5)
> (In reply to comment #4)
> > Seems fine on my end, does it work for you?
> 
> Jose? Does this work for you?

I am so sorry for answering so late.

Yes it works for me thank you.
Comment 7 Anthony Hunter CLA 2009-11-26 17:28:20 EST
Committed to HEAD and R3_5_maintenance.