McFoggy/cssfx

NPE when adding stylesheets

dlemmermann opened this issue · 8 comments

For my new ShowcaseFX view / app I constantly need to add and remove stylesheets. When doing to I keep getting this NPE:

Exception in thread "JavaFX Application Thread" java.lang.NullPointerException
	at java.base/java.util.regex.Matcher.getTextLength(Matcher.java:1770)
	at java.base/java.util.regex.Matcher.reset(Matcher.java:416)
	at java.base/java.util.regex.Matcher.<init>(Matcher.java:253)
	at java.base/java.util.regex.Pattern.matcher(Pattern.java:1133)
	at fr.brouillard.oss.cssfx@11.5.0/fr.brouillard.oss.cssfx.impl.CSSFXMonitor$URIRegistrar.classpathToURI(CSSFXMonitor.java:319)
	at fr.brouillard.oss.cssfx@11.5.0/fr.brouillard.oss.cssfx.impl.CSSFXMonitor$URIRegistrar.register(CSSFXMonitor.java:342)
	at fr.brouillard.oss.cssfx@11.5.0/fr.brouillard.oss.cssfx.impl.CSSFXMonitor$StyleSheetChangeListener.onChanged(CSSFXMonitor.java:399)
	at javafx.base/com.sun.javafx.collections.ListListenerHelper$Generic.fireValueChangedEvent(ListListenerHelper.java:329)
	at javafx.base/com.sun.javafx.collections.ListListenerHelper.fireValueChangedEvent(ListListenerHelper.java:73)
	at javafx.base/javafx.collections.ObservableListBase.fireChange(ObservableListBase.java:239)
	at javafx.base/javafx.collections.ListChangeBuilder.commit(ListChangeBuilder.java:482)
	at javafx.base/javafx.collections.ListChangeBuilder.endChange(ListChangeBuilder.java:541)
	at javafx.base/javafx.collections.ObservableListBase.endChange(ObservableListBase.java:211)
	at javafx.base/javafx.collections.ModifiableObservableListBase.addAll(ModifiableObservableListBase.java:109)
	at com.dlsc.showcasefx@0.0.6/com.dlsc.showcase.impl.CssShowcaseViewSkin.updateStylesheets(CssShowcaseViewSkin.java:103)
	at com.dlsc.showcasefx@0.0.6/com.dlsc.showcase.impl.CssShowcaseViewSkin.lambda$new$0(CssShowcaseViewSkin.java:90)

It should be noted that the stylesheet is actually not on the class path but dropped by the user onto the app.

is it reproducible directly with your ShowcaseFX app ?

Yes, just drop a couple of CSS files on it, switch between them, etc...

@dlemmermann I do not reproduce:

  • I launched the app with ./mvnw javafx:run
  • I added several css files with content like
/*
comment
*/
.section-label {
   -fx-text-fill: red;
   -fx-font-size: 3em;
}
  • I can switch in your UI from one to the other

Changing the css file content is not reflected in the app but I do not see any NPE logged.

Do you have reproducer steps?

Changing the css file content is not reflected in the app

see my PR in dlsc-software-consulting-gmbh/ShowcaseFX#4

Yes, just drop a couple of CSS files on it, switch between them, etc...

@dlemmermann please detail how to get the error, I could not reproduce for now, see above.

I only get the error when I do a drag and drop of MULTIPLE css files at the same time.

Never mind ... I found out what the issue was. My code was adding multiple configurations to the view when dropping multiple files. One config per file. This then caused each config to be selected, which removed the stylesheets from the previous config, and so on ..... obviously messy.