FSchumacher commented on a change in pull request #696:
URL: https://github.com/apache/jmeter/pull/696#discussion_r792827021



##########
File path: 
src/core/src/test/java/org/apache/jmeter/gui/util/JSyntaxTextAreaTest.java
##########
@@ -41,7 +45,37 @@ public void testSetLanguage() {
             textArea.setLanguage(null);
             assertEquals(SyntaxConstants.SYNTAX_STYLE_NONE, 
textArea.getSyntaxEditingStyle());
         } catch (HeadlessException he) {
-            // Does not work in headless mode
+            // Does not work in headless mode, which depends on value of 
java.awt.headless property
+            // and the OS (e.g. might work on MacOS and not on Linux due to 
missing X11).
+            System.out.println("WARNING for 
JSyntaxTextAreaTest.testSetLanguage test: does not work in headless mode");
+        }
+    }
+
+    @Test
+    public void testHeadless() {
+        String key = "java.awt.headless";
+        String initialValue = System.getProperty(key);
+        try {
+            System.setProperty(key, "true");

Review comment:
       Is this really a sane way to test headless mode?

##########
File path: src/core/src/main/java/org/apache/jmeter/gui/action/Save.java
##########
@@ -92,7 +92,7 @@
     private static final int BACKUP_MAX_COUNT = 
JMeterUtils.getPropDefault(JMX_BACKUP_MAX_COUNT, 10);
 
     // NumberFormat to format version number in backup file names
-    private static final DecimalFormat BACKUP_VERSION_FORMATER = new 
DecimalFormat("000000"); //$NON-NLS-1$
+    private static final DecimalFormat BACKUP_VERSION_FORMAT = new 
DecimalFormat("000000"); //$NON-NLS-1$

Review comment:
       This has nothing to do with the description of the issue. I don't think 
it is needed here and should be done in it's own PR (if at all).

##########
File path: 
src/core/src/test/java/org/apache/jmeter/gui/util/JSyntaxTextAreaTest.java
##########
@@ -41,7 +45,37 @@ public void testSetLanguage() {
             textArea.setLanguage(null);
             assertEquals(SyntaxConstants.SYNTAX_STYLE_NONE, 
textArea.getSyntaxEditingStyle());
         } catch (HeadlessException he) {
-            // Does not work in headless mode
+            // Does not work in headless mode, which depends on value of 
java.awt.headless property
+            // and the OS (e.g. might work on MacOS and not on Linux due to 
missing X11).
+            System.out.println("WARNING for 
JSyntaxTextAreaTest.testSetLanguage test: does not work in headless mode");
+        }
+    }
+
+    @Test
+    public void testHeadless() {
+        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'
+            JSyntaxTextArea textArea = JSyntaxTextArea.getInstance(10,20);
+
+            String myText = "my text";
+            textArea.setText(myText);
+            // next one fails with NPE when getInstance does not provide 
overridden method
+            textArea.setCodeFoldingEnabled(true);
+            assertEquals(myText, textArea.getText());
+
+        } catch (HeadlessException he) {
+            fail("WARNING: Does not work in headless mode");

Review comment:
       Is this expected? I would expect, that this fail should never be reached 
and should point this out a bit more clearly.

##########
File path: 
src/core/src/test/java/org/apache/jmeter/gui/util/JSyntaxTextAreaTest.java
##########
@@ -41,7 +45,37 @@ public void testSetLanguage() {
             textArea.setLanguage(null);
             assertEquals(SyntaxConstants.SYNTAX_STYLE_NONE, 
textArea.getSyntaxEditingStyle());
         } catch (HeadlessException he) {
-            // Does not work in headless mode
+            // Does not work in headless mode, which depends on value of 
java.awt.headless property
+            // and the OS (e.g. might work on MacOS and not on Linux due to 
missing X11).
+            System.out.println("WARNING for 
JSyntaxTextAreaTest.testSetLanguage test: does not work in headless mode");
+        }
+    }
+
+    @Test
+    public void testHeadless() {
+        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'
+            JSyntaxTextArea textArea = JSyntaxTextArea.getInstance(10,20);
+
+            String myText = "my text";
+            textArea.setText(myText);

Review comment:
       Are you testing set/getText here, or the creation of a specialised 
subclass?

##########
File path: 
src/core/src/main/java/org/apache/jmeter/gui/util/JSyntaxTextArea.java
##########
@@ -118,7 +119,15 @@ public void setCaretPosition(int b) { }
                     @Override
                     public void discardAllEdits() { }
                     @Override
-                    public void setText(String t) { }
+                    public void setText(String t) {

Review comment:
       If I add a `super.setText(t)` here, I get the following stacktrace:
   ```
   java.lang.NullPointerException
           at 
org.fife.ui.rsyntaxtextarea.RSyntaxTextArea.getFontMetricsForTokenType(RSyntaxTextArea.java:1204)
           at 
org.fife.ui.rsyntaxtextarea.TokenImpl.getWidthUpTo(TokenImpl.java:578)
           at org.fife.ui.rsyntaxtextarea.TokenImpl.getWidth(TokenImpl.java:570)
           at 
org.fife.ui.rsyntaxtextarea.WrappedSyntaxView.calculateBreakPosition(WrappedSyntaxView.java:127)
           at 
org.fife.ui.rsyntaxtextarea.WrappedSyntaxView$WrappedLine.calculateLineCount(WrappedSyntaxView.java:1191)
           at 
org.fife.ui.rsyntaxtextarea.WrappedSyntaxView$WrappedLine.handleDocumentEvent(WrappedSyntaxView.java:1440)
           at 
org.fife.ui.rsyntaxtextarea.WrappedSyntaxView$WrappedLine.insertUpdate(WrappedSyntaxView.java:1464)
           at 
org.fife.ui.rsyntaxtextarea.WrappedSyntaxView.insertUpdate(WrappedSyntaxView.java:705)
           at 
javax.swing.plaf.basic.BasicTextUI$RootView.insertUpdate(BasicTextUI.java:1610)
           at 
javax.swing.plaf.basic.BasicTextUI$UpdateHandler.insertUpdate(BasicTextUI.java:1869)
           at 
javax.swing.text.AbstractDocument.fireInsertUpdate(AbstractDocument.java:201)
           at 
org.fife.ui.rsyntaxtextarea.RSyntaxDocument.fireInsertUpdate(RSyntaxDocument.java:187)
           at 
javax.swing.text.AbstractDocument.handleInsertString(AbstractDocument.java:748)
           at 
javax.swing.text.AbstractDocument.insertString(AbstractDocument.java:707)
           at 
javax.swing.text.PlainDocument.insertString(PlainDocument.java:130)
           at 
javax.swing.text.AbstractDocument.replace(AbstractDocument.java:669)
           at javax.swing.text.JTextComponent.setText(JTextComponent.java:1669)
           at 
org.apache.jmeter.gui.util.JSyntaxTextArea$1.setText(JSyntaxTextArea.java:122)
   ```
   So, I would say, no, it does not resolve the issue :)

##########
File path: 
src/core/src/test/java/org/apache/jmeter/gui/util/JSyntaxTextAreaTest.java
##########
@@ -41,7 +45,37 @@ public void testSetLanguage() {
             textArea.setLanguage(null);
             assertEquals(SyntaxConstants.SYNTAX_STYLE_NONE, 
textArea.getSyntaxEditingStyle());
         } catch (HeadlessException he) {
-            // Does not work in headless mode
+            // Does not work in headless mode, which depends on value of 
java.awt.headless property
+            // and the OS (e.g. might work on MacOS and not on Linux due to 
missing X11).

Review comment:
       I don't understand this new comment. Can you explain it to me?




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to