JDK-6563734 : Path2D.Float and Path2D.Double should have final getPathIterator methods
  • Type: Bug
  • Status: Closed
  • Resolution: Fixed
  • Component: client-libs
  • Sub-Component: 2d
  • Priority: P3
  • Affected Version: 6
  • OS: generic
  • CPU: generic
  • Submit Date: 2007-05-30
  • Updated Date: 2017-05-16
  • Resolved Date: 2011-05-23
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 Availabitlity Release.

To download the current JDK release, click here.
7 b142Fixed
When the Path2D class and its type-specific subclasses were all created, the
new classes were all left non-final for a couple of reasons:

- GeneralPath needed to subclass Path2D.Float so Path2D.Float could not be final
- there was an existing bug against GeneralPath being final

To satisfy these two design issues we decided to make the classes non-final, but
to make all of the method implementations final so that developers could create
"decorated subclasses" with additional non-geometric functionality, but so that
we could retain strict control over the implementation to enable optimizing
assumptions to be made.

The problem with the plan is that we left 2 methods non-final:

- Path2D.Float.getPathIterator(AffineTransform)
- Path2D.Double.getPathIterator(AffineTransform)

This is sloppy and it creates a practical problem in that there is nothing in
the method signature that prevents a rogue class from subclassing these variants
and returning a Path Iterator that produces different geometry.

There are several reasons why anyone taking advantage of this override hole
would be unhappy in the attempt.  First, there are several places in the JDK
where we examine an object, discover that it is one of the known subclasses
of Path2D, and bypass the methods and work on it directly.  These include
(but not limited to):

new Path2D.Float/Double(Path2D)

Second, there are other final methods on Path2D which produce answers based
on the internal representation of the geometry, rather than based on the
geometry that might be expressed by the PathIterator.  These methods include:


Lastly, there is no really compelling reason why someone would want to override
this method other than "because they can".  The lack of any useful purpose in
overriding the method, in addition to the problems outlined above that one might
encounter if one were to attempt do do this, both recommend that the compatibility
hit to add "final" to the method signature would be warranted in this case.

EVALUATION Fixed by making the 3 methods final: Path2D.getPathIterator(AffineTransform, double) Path2D.Float.getPathIterator(AffineTransform) Path2D.Double.getPathIterator(AffineTransform)

SUGGESTED FIX Add "final" to the methods: - Path2D.Float.getPathIterator(AffineTransform) - Path2D.Double.getPathIterator(AffineTransform) - Path2D.getPathIterator(AffineTransform, flatness)