java-native-access/jna · error · RuntimeException
Area is not polygonal: " + area
Error message
Area is not polygonal: " + area
What it means
W32WindowUtils converts a java.awt.Area into a Win32 polygon region for setWindowMask by walking its PathIterator and accepting only SEG_LINETO/SEG_MOVETO/SEG_CLOSE segments. If the Area contains curves (SEG_QUADTO, SEG_CUBICTO, arcs, ovals), the code throws RuntimeException('Area is not polygonal: <area>').
Source
Thrown at contrib/platform/src/com/sun/jna/platform/WindowUtils.java:1068
float[] coords = new float[6];
List<POINT> points = new ArrayList<>();
int size = 0;
List<Integer> sizes = new ArrayList<>();
while (!pi.isDone()) {
int type = pi.currentSegment(coords);
if (type == PathIterator.SEG_MOVETO) {
size = 1;
points.add(new POINT((int)coords[0], (int)coords[1]));
}
else if (type == PathIterator.SEG_LINETO) {
++size;
points.add(new POINT((int)coords[0], (int)coords[1]));
}
else if (type == PathIterator.SEG_CLOSE) {
sizes.add(Integer.valueOf(size));
}
else {
throw new RuntimeException("Area is not polygonal: " + area);
}
pi.next();
}
POINT[] lppt = (POINT[])new POINT().toArray(points.size());
POINT[] pts = points.toArray(new POINT[points.size()]);
for (int i=0;i < lppt.length;i++) {
lppt[i].x = pts[i].x;
lppt[i].y = pts[i].y;
}
int[] counts = new int[sizes.size()];
for (int i=0;i < counts.length;i++) {
counts[i] = sizes.get(i).intValue();
}
HRGN hrgn = gdi.CreatePolyPolygonRgn(lppt, counts, counts.length, mode);
setWindowRegion(w, hrgn);
}
@OverrideView on GitHub (pinned to d036ad9781)
Solutions
- Flatten the shape before building the Area: new Area(shape.getPathIterator(null, flatness)) — flattening converts curves to line segments.
- Build the mask from Polygon/rectangular shapes only, or approximate curves with many line segments.
- Use a newer JNA version if available (later releases handle non-polygonal areas by flattening).
- Catch RuntimeException and fall back to a rectangular mask.
Example fix
// before
Area area = new Area(new Ellipse2D.Float(0, 0, 200, 200));
WindowUtils.setWindowMask(frame, area); // RuntimeException: not polygonal
// after
Area area = new Area(
new Ellipse2D.Float(0, 0, 200, 200).getPathIterator(null, 1.0)); // flattened to line segments
WindowUtils.setWindowMask(frame, area); Defensive patterns
Strategy: validation
Validate before calling
PathIterator pi = area.getPathIterator(null);
boolean polygonal = true;
while (!pi.isDone()) { int t = pi.currentSegment(new double[6]); if (t == PathIterator.SEG_QUADTO || t == PathIterator.SEG_CUBICTO) { polygonal = false; break; } pi.next(); }
if (!polygonal) { area = new Area(shape.getPathIterator(null, 1.0)); } Try / catch
try { WindowUtils.setWindowMask(frame, area); } catch (RuntimeException e) { WindowUtils.setWindowMask(frame, new Area(frame.getBounds())); } Prevention
- Always flatten curved shapes before constructing the mask Area
- Prefer PathIterator(null, flatness) when building Areas from ovals/arcs
- Use newer JNA releases that flatten areas internally
- Test shaped windows with every shape type your app generates
When it happens
Trigger: Calling WindowUtils.setWindowMask(window, area) where the Area was built from curves: new Area(new Ellipse2D.Float(...)), new Area(new RoundRectangle2D...), or any shape whose outline flattens to quadratic/cubic segments without prior flattening.
Common situations: Making rounded or elliptical window shapes with setWindowMask(Area) using oval/round-rect shapes directly; building Areas from Arc2D; forgetting that Area retains curve segments unless flattened.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
- Set sun.java2d.noddraw=true to enable transparent windows
- Window must be a RootPaneContainer
- Component must be heavyweight: " + w
- No support for " + os
- Property Accessor name must start with 'get', or set the ano
AI-assisted analysis of java-native-access/jna@d036ad9781 (2026-09-12).
Data as JSON: /api/errors/c0ca65fe022dbe1e.
Report an issue: GitHub.