JDK-8042103 : Deserialization of empty java.awt.geom.Path2D will cause an exception
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 7,8,9
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • OS: os_x
  • Submitted: 2013-03-20
  • Updated: 2014-07-29
  • Resolved: 2014-06-11
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 8 JDK 9
8u20Fixed 9 b22Fixed
Description
FULL PRODUCT VERSION :


A DESCRIPTION OF THE PROBLEM :
If a Path2D object has none path segments and its capacity is 0, then call  its moveTo() method  will cause an exception(java.lang.ArrayIndexOutOfBoundsException: 0).

My application includes several Path objects and these objects need to be serialized.If one object before serialization call reset () method, and its capacity will be 0.This object is deserialized will be unavailable because it has lost the ability to increase capacity.

I found Path2D.needRoom(...) cause this issue by check the java source code.

Others will cause an empty Path2D object (except of deserialization):
1.Path2D path = Path2D.Float(int rule, int initialCapacity);   while initialCapacity is 0
2.Path2D path = Path2D.Double(int rule, int initialCapacity);
3.Path2D path = Path2D.Float(Shape s);   while s is empty Path2D
4.Path2D path = Path2D.Float(Shape s, AffineTransform at);
5.Path2D path = Path2D.Double(Shape s);
6.Path2D path = Path2D.Double(Shape s, AffineTransform at);

Please pardon me for my English.



REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
Path2D myPath1,myPath2;

myPath1 = new Path2D.Double();
......
myPath1.reset();

ObjectOutputStream oos = new ObjectOutputStream(...);
oos.writeObject(myPath);

ObjectInputStream ois = new ObjectInputStream(...);
myPath2 = (Path2D)ois.readObject();

myPath2.moveTo(10,10);  //  throw java.lang.ArrayIndexOutOfBoundsException:0
---------- END SOURCE ----------
Comments
Path2D.needRoom() should grow the capacity by INIT_SIZE if default capacity is 0.
30-04-2014

Unclear if the details provided are sufficient to evaluate, but moved over for consideration vs JDK 9. This may still close as incomplete.
29-04-2014