{"record":{"id":"c0ca65fe022dbe1e","repo":"java-native-access/jna","slug":"area-is-not-polygonal-area","errorCode":null,"errorMessage":"Area is not polygonal: \" + area","messagePattern":"Area is not polygonal: \" \\+ area","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"contrib/platform/src/com/sun/jna/platform/WindowUtils.java","lineNumber":1068,"sourceCode":"            float[] coords = new float[6];\n            List<POINT> points = new ArrayList<>();\n            int size = 0;\n            List<Integer> sizes = new ArrayList<>();\n            while (!pi.isDone()) {\n                int type = pi.currentSegment(coords);\n                if (type == PathIterator.SEG_MOVETO) {\n                    size = 1;\n                    points.add(new POINT((int)coords[0], (int)coords[1]));\n                }\n                else if (type == PathIterator.SEG_LINETO) {\n                    ++size;\n                    points.add(new POINT((int)coords[0], (int)coords[1]));\n                }\n                else if (type == PathIterator.SEG_CLOSE) {\n                    sizes.add(Integer.valueOf(size));\n                }\n                else {\n                    throw new RuntimeException(\"Area is not polygonal: \" + area);\n                }\n                pi.next();\n            }\n            POINT[] lppt = (POINT[])new POINT().toArray(points.size());\n            POINT[] pts = points.toArray(new POINT[points.size()]);\n            for (int i=0;i < lppt.length;i++) {\n                lppt[i].x = pts[i].x;\n                lppt[i].y = pts[i].y;\n            }\n            int[] counts = new int[sizes.size()];\n            for (int i=0;i < counts.length;i++) {\n                counts[i] = sizes.get(i).intValue();\n            }\n            HRGN hrgn = gdi.CreatePolyPolygonRgn(lppt, counts, counts.length, mode);\n            setWindowRegion(w, hrgn);\n        }\n\n        @Override","sourceCodeStart":1050,"sourceCodeEnd":1086,"githubUrl":"https://github.com/java-native-access/jna/blob/d036ad9781adad4b66693e8fa7098e4ac665e0a3/contrib/platform/src/com/sun/jna/platform/WindowUtils.java#L1050-L1086","documentation":"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>').","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nArea area = new Area(new Ellipse2D.Float(0, 0, 200, 200));\nWindowUtils.setWindowMask(frame, area); // RuntimeException: not polygonal\n// after\nArea area = new Area(\n    new Ellipse2D.Float(0, 0, 200, 200).getPathIterator(null, 1.0)); // flattened to line segments\nWindowUtils.setWindowMask(frame, area);","handlingStrategy":"validation","validationCode":"PathIterator pi = area.getPathIterator(null);\nboolean polygonal = true;\nwhile (!pi.isDone()) { int t = pi.currentSegment(new double[6]); if (t == PathIterator.SEG_QUADTO || t == PathIterator.SEG_CUBICTO) { polygonal = false; break; } pi.next(); }\nif (!polygonal) { area = new Area(shape.getPathIterator(null, 1.0)); }","typeGuard":null,"tryCatchPattern":"try { WindowUtils.setWindowMask(frame, area); } catch (RuntimeException e) { WindowUtils.setWindowMask(frame, new Area(frame.getBounds())); }","preventionTips":["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"],"tags":["java","jna","swing","window-shaping","geometry"],"backgroundTag":"invalid-argument-value","analyzedSha":"d036ad9781adad4b66693e8fa7098e4ac665e0a3","analyzedAt":"2026-09-12T06:50:59.239Z","contentChangedAt":"2026-09-12T06:50:59.239Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}