public static JSyntaxTextArea getInstance(int rows, int cols, boolean disableUndo) {
        try {
            JSyntaxTextArea jSyntaxTextArea = new JSyntaxTextArea(rows, cols, disableUndo);
            JFactory.withDynamic(jSyntaxTextArea, JSyntaxTextArea::applyTheme);
            // Gutter styling is only applied if the text area is contained in a scroll pane.
            jSyntaxTextArea.addHierarchyListener(GUTTER_THEME_PATCHER);
            return jSyntaxTextArea;
        } catch (HeadlessException e) {
            // Allow override for unit testing only
            if ("true".equals(System.getProperty("java.awt.headless"))) { // $NON-NLS-1$ $NON-NLS-2$
                return new JSyntaxTextArea(disableUndo) {
                    private String savedText = "";
                    private static final long serialVersionUID = 1L;
                    @Override
                    protected void init() {
                        try {
                            super.init();
                        } catch (HeadlessException|NullPointerException e) {
                            // ignored
                        }
                    }
                    // Override methods that would fail
                    @Override
                    public void setCodeFoldingEnabled(boolean b) {  }
                    @Override
                    public void setCaretPosition(int b) { }
                    @Override
                    public void discardAllEdits() { }
                    @Override
                    public void setText(String t) {
                        savedText = t;
                    }

                    @Override
                    public String getText() {
                        return savedText;
                    }

                    @Override
                    public boolean isCodeFoldingEnabled(){ return true; }
                };
            } else {
                throw e;
            }
        }
    }
@Test
    public void testHeadlessGetText() {
        String key = "java.awt.headless";
        String initialValue = System.getProperty(key);
        try {
            System.setProperty(key, "true");
            // getInstance() returns anonymous class with some overridden methods
            // to avoid errors due to 'java.awt.headless=true'.
            // E.g. it should not throw a HeadlessException.
            JSyntaxTextArea textArea = JSyntaxTextArea.getInstance(10,20);

            String myText = "my text";
            textArea.setText(myText);
            assertEquals(myText, textArea.getText());
        } finally {
            if (initialValue != null) {
                System.setProperty(key, initialValue);
            }
            else {
                System.clearProperty(key);
            }
        }
    }