JDK-8076419 : Path2D copy constructors and clone method propagate size of arrays from source path
  • Type: Bug
  • Component: client-libs
  • Sub-Component: 2d
  • Affected Version: 9
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2015-03-31
  • Updated: 2015-09-29
  • Resolved: 2015-04-01
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
8u60Fixed 9 b61Fixed
Description
The copy constructors and clone method on the Path2D classes all set the internal arrays for the new objects to the size of the arrays for the source objects.  Since the copies are typically done to save a path aside, or to return an "effectively immutable" answer from a method, the added room for growth is not needed - only the existing path segments need to be saved.

The waste is normally minor, but for a program that uses a single scratch path to accumulate paths of varying sizes and then clones or copies it as a return value, over time that scratch path may grow large, but the subsequent results it is calculating may be much smaller.  The issue is that as the scratch path grows, so does the size of its result values - regardless of the complexity of the subsequent results.

The copy constructors should only create new arrays in the new paths large enough for the path segments already stored in the source path.