Skip to content

Commit

Permalink
Add check on errorProperty
Browse files Browse the repository at this point in the history
  • Loading branch information
hjohn committed Jul 22, 2024
1 parent ddfd0cf commit 6c5b771
Showing 1 changed file with 100 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
import com.sun.javafx.tk.Toolkit;
import java.io.IOException;
import javafx.css.CssParser;
import javafx.css.CssParser.ParseError;
import javafx.css.CssParser.ParseError.PropertySetError;
import javafx.css.PseudoClass;
import javafx.css.Stylesheet;
import javafx.geometry.Insets;
Expand Down Expand Up @@ -684,6 +686,33 @@ public void shouldDetectSimpleInfiniteLoop() throws IOException {
root.getChildren().addAll(a);

assertDoesNotThrow(() -> stage.show()); // This should not result in a StackOverflowError
assertEquals(1, CssParser.errorsProperty().size());

ParseError error = CssParser.errorsProperty().getFirst();

assertEquals(PropertySetError.class, error.getClass());

// Note: on Windows, the message is using inconsistent line endings (sometimes Windows, sometimes Linux)
// so I've stripped it.
assertEquals(
"""
Caught java.lang.IllegalArgumentException: Loop detected in *.root{
\t-fx-base-fill: <Value lookup="true">
<value>-fx-base</value>
<converter>null</converter>
</Value>
\t-fx-base: <Value lookup="true">
<value>-fx-base-color</value>
<converter>null</converter>
</Value>
\t-fx-base-color: <Value lookup="true">
<value>-fx-base-fill</value>
<converter>null</converter>
</Value>
} while resolving '-fx-base'' while calculating value for '-fx-background-color' from rule '*.pane' in stylesheet userAgentStyleSheet\
""",
error.getMessage().replace("\r", "")
);
}

@Test
Expand All @@ -710,5 +739,76 @@ public void shouldDetectNestedInfiniteLoop() throws IOException {
root.getChildren().addAll(a);

assertDoesNotThrow(() -> stage.show()); // This should not result in a StackOverflowError
assertEquals(1, CssParser.errorsProperty().size());

ParseError error = CssParser.errorsProperty().getFirst();

assertEquals(PropertySetError.class, error.getClass());

// Note: on Windows, the message is using inconsistent line endings (sometimes Windows, sometimes Linux)
// so I've stripped it.
assertEquals(
"""
Caught java.lang.IllegalArgumentException: Loop detected in *.root{
\t-fx-base-fill: <Value>
<value values="3">
<Value lookup="true">
<value>-fx-base</value>
<converter>null</converter>
</Value> <Value>
<value values="2">
<Value>
<value>49.0%</value>
<converter>null</converter>
</Value> <Value>
<value>0xffffffff</value>
<converter>null</converter>
</Value> </value>
<converter>StopConverter</converter>
</Value> <Value>
<value values="2">
<Value>
<value>50.0%</value>
<converter>null</converter>
</Value> <Value>
<value>0x000000ff</value>
<converter>null</converter>
</Value> </value>
<converter>StopConverter</converter>
</Value> </value>
<converter>LadderConverter</converter>
</Value>
\t-fx-base: <Value>
<value values="3">
<Value lookup="true">
<value>-fx-base-fill</value>
<converter>null</converter>
</Value> <Value>
<value values="2">
<Value>
<value>49.0%</value>
<converter>null</converter>
</Value> <Value>
<value>0xffffffff</value>
<converter>null</converter>
</Value> </value>
<converter>StopConverter</converter>
</Value> <Value>
<value values="2">
<Value>
<value>50.0%</value>
<converter>null</converter>
</Value> <Value>
<value>0x000000ff</value>
<converter>null</converter>
</Value> </value>
<converter>StopConverter</converter>
</Value> </value>
<converter>LadderConverter</converter>
</Value>
} while resolving '-fx-base'' while calculating value for '-fx-background-color' from rule '*.pane' in stylesheet userAgentStyleSheet\
""",
error.getMessage().replace("\r", "")
);
}
}

0 comments on commit 6c5b771

Please sign in to comment.