You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@royale.apache.org by jo...@apache.org on 2024/04/22 17:31:30 UTC

(royale-compiler) 01/02: CSSDocument: fix null exception when contains only comments (closes #1218)

This is an automated email from the ASF dual-hosted git repository.

joshtynjala pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/royale-compiler.git

commit 79276bf122b05d1553eaa0616fdb6936da39d272
Author: Josh Tynjala <jo...@apache.org>
AuthorDate: Mon Apr 22 10:30:41 2024 -0700

    CSSDocument: fix null exception when <fx:Style> contains only comments (closes #1218)
---
 RELEASE_NOTES.md                                                  | 1 +
 .../java/org/apache/royale/compiler/internal/css/CSSDocument.java | 8 +++++++-
 2 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md
index db78f46f5..05d0d23c4 100644
--- a/RELEASE_NOTES.md
+++ b/RELEASE_NOTES.md
@@ -24,6 +24,7 @@ Apache Royale Compiler 0.9.11
 - compiler: Fix overflow exception caused by `uint` values that overflowed an integer in the compiler.
 - compiler: Fix incorrect error or warning positions for CSS content inside `<fx:Style>` tag.
 - compiler: Fix non-string values in an MXML array sometimes getting incorrectly wrapped in quotes when emitting JavaScript.
+- compiler: Fix null exception for `<fx:Style>` tags that contain only comments.
 - debugger: Fix exception when evaluating certain expressions at run-time.
 - formatter: Added `insert-new-line-else` configuration option.
 - formatter: Filtered out unnecessary compiler warnings.
diff --git a/compiler/src/main/java/org/apache/royale/compiler/internal/css/CSSDocument.java b/compiler/src/main/java/org/apache/royale/compiler/internal/css/CSSDocument.java
index 978df55b4..b59c4d521 100644
--- a/compiler/src/main/java/org/apache/royale/compiler/internal/css/CSSDocument.java
+++ b/compiler/src/main/java/org/apache/royale/compiler/internal/css/CSSDocument.java
@@ -72,7 +72,13 @@ public class CSSDocument extends CSSNodeBase implements ICSSDocument
             final CommonTokenStream tokens = new CommonTokenStream(lexer);
             final CSSParser parser = new CSSParser(tokens);
             final CSSParser.stylesheet_return stylesheet = parser.stylesheet();
-            final CommonTree ast = (CommonTree)stylesheet.getTree();
+            CommonTree ast = (CommonTree)stylesheet.getTree();
+            if (ast == null)
+            {
+                // may be null if the input contains only comments -JT
+                // apache/royale-compiler#1218
+                ast = new CommonTree();
+            }
             final CommonTreeNodeStream nodes = new CommonTreeNodeStream(ast);
             nodes.setTokenStream(tokens);