[OpenJDK 2D-Dev] JDK9: RFR: 8039342: Fix raw and unchecked warnings in sun.awt.*
Jim Graham
james.graham at oracle.com
Wed Apr 23 21:20:13 UTC 2014
Given how vectors of curves are constructed, either they are the output
of a previous operation, in which case you need enough curves/edges to
enclose an area and the count must be 0 or >=2, or they are the result
of ingesting a Shape. Looking at the code that ingests a Shape in
Area.pathToCurves, I thought I could find ways of getting it to generate
just a single path segment, but there was always some logic that
eventually prevented it from getting to pruneEdges.
For instance, an empty path ends up with no segments because it only
gets a single "insertLine(0,0,0,0)" after the PathIterator loop and
insertLine() itself prunes out that segment and ends up with an empty
Vector before the path is validated (via NZOp.calculate() or
EOop.calculate()).
If you just have a moveTo, it tries to insertLine(0,0,0,0) to close off
the old path which doesn't insert anything, then it inserts an Order0
moveto point, then it ends with closing off the final path with another
insertLine(0,0,0,0) which ends up getting ignored. This gives you a
Vector of 1 Curve, but it is an Order0 and so it gets pruned out by the
addEdges() method before that list ever gets to pruneEdges.
If you have moveTo+something else like a lineto, then you get:
moveto - insertLine(0,0,0,0), ignored - insertMove(x1,y1), adds an Order0
lineto - insertLine(x1,y1,x2,y2), adds a line segment
post-pathiterator - insertline(x2,y2,x1,y1), adds a line segment
This ends up with 2 curves in the edges list which does not trigger the
bad code, but both get eliminated during the cleanup and normalization
and the resulting Area object has an empty vector. But, for our
purposes, we got to pruneEdges with 2 edges.
Finally, I even went so far as to create a bogus shape that skipped
having a moveto and just had a lineto (I had to implement Shape
directly) and even that ended up with a line segment out, and then a
closing line segment back which had >=2 segments.
So, it appears that either an ingested shape will have at least 2
non-empty, non-Order0 segments, or it will have none.
So, that code is "just in case the laws of physics change" code and it
was buggy, but was provably-ish never callable. I imagine that these
generics mechanisms would have been a god-send, though, back when I was
actually writing and debugging all of this...
...jim
On 4/7/14 1:46 PM, Henry Jen wrote:
> Hi,
>
> Please review the webrev cleans up raw and unchecked warnings in sun.awt,
>
> http://cr.openjdk.java.net/~henryjen/jdk9/8039342/0/webrev/
>
> The following changes in AreaOp::pruneEdges() is particular worth
> attention, when numedges < 2, two different type are mixed up in the
> past with use of rawtypes; However, I think it could only work if the
> Vector is empty?
>
> Cheers,
> Henry
>
>
>> @@ -193,16 +193,20 @@
>> }
>> return 1;
>> }
>> };
>>
>> - private Vector pruneEdges(Vector edges) {
>> + private Vector<Curve> pruneEdges(Vector<Edge> edges) {
>> int numedges = edges.size();
>> if (numedges < 2) {
>> - return edges;
>> + Vector<Curve> rt = new Vector<>();
>> + for (Edge edge: edges) {
>> + rt.add(edge.getCurve());
>> }
>> - Edge[] edgelist = (Edge[]) edges.toArray(new Edge[numedges]);
>> + return rt;
>> + }
>> + Edge[] edgelist = edges.toArray(new Edge[numedges]);
>> Arrays.sort(edgelist, YXTopComparator);
>> if (false) {
>> System.out.println("pruning: ");
>> for (int i = 0; i < numedges; i++) {
>> System.out.println("edgelist["+i+"] = "+edgelist[i]);
>
More information about the 2d-dev
mailing list