2017-09-03 1 views
-1

J'ai un test JavaFX qui échoue uniquement dans les fenêtres, mais fonctionne très bien dans Mac OS X et LinuxJavaFX test qui échoue dans Windows et fonctionne dans Mac OS X et Linux

Voici le stacktrace:

Edit: 1

Running com.myproject.meditor.SLIVCodeAreaTest 
Tests run: 17, Failures: 0, Errors: 17, Skipped: 0, Time elapsed: 6.656 sec <<< FAILURE! - in com.myproject.meditor.SLIVCodeAreaTest 
testRHBlock(com.myproject.meditor.SLIVCodeAreaTest) Time elapsed: 0 sec <<< ERROR! 
java.lang.ExceptionInInitializerError: null 
    at com.sun.glass.ui.Screen.getScreens(Screen.java:70) 
    at com.sun.glass.ui.Screen.getMainScreen(Screen.java:61) 
    at com.sun.javafx.font.PrismFontFactory.getSystemFontSize(PrismFontFactory.java:1911) 
    at com.sun.javafx.font.PrismFontLoader.getSystemFontSize(PrismFontLoader.java:240) 
    at javafx.scene.text.Font.getDefaultSystemFontSize(Font.java:71) 
    at javafx.scene.text.Font.getDefault(Font.java:86) 
    at javafx.scene.text.Text.getFont(Text.java:478) 
    at javafx.scene.text.Text.getFontInternal(Text.java:487) 
    at javafx.scene.text.Text.access$100(Text.java:95) 
    at javafx.scene.text.Text$1.getFont(Text.java:206) 
    at com.sun.javafx.text.GlyphLayout.breakRuns(GlyphLayout.java:174) 
    at com.sun.javafx.text.PrismTextLayout.buildRuns(PrismTextLayout.java:770) 
    at com.sun.javafx.text.PrismTextLayout.layout(PrismTextLayout.java:1021) 
    at com.sun.javafx.text.PrismTextLayout.ensureLayout(PrismTextLayout.java:223) 
    at com.sun.javafx.text.PrismTextLayout.getBounds(PrismTextLayout.java:246) 
    at javafx.scene.text.TextFlow.computePrefWidth(TextFlow.java:203) 
    at javafx.scene.Parent.prefWidth(Parent.java:915) 
    at javafx.scene.layout.Region.prefWidth(Region.java:1419) 
    at org.fxmisc.richtext.ParagraphBox.computePrefWidth(ParagraphBox.java:199) 
    at org.fxmisc.richtext.ParagraphBox.computeMinWidth(ParagraphBox.java:191) 
    at javafx.scene.Parent.minWidth(Parent.java:943) 
    at javafx.scene.layout.Region.minWidth(Region.java:1383) 
    at org.fxmisc.flowless.VerticalHelper.minBreadth(OrientationHelper.java:234) 
    at org.fxmisc.flowless.OrientationHelper.minBreadth(OrientationHelper.java:44) 
    at org.reactfx.collection.MappedList.get(MappedList.java:27) 
    at org.reactfx.collection.MemoizationListImpl.force(MemoizationList.java:121) 
    at org.fxmisc.flowless.SizeTracker.breadthFor(SizeTracker.java:161) 
    at org.fxmisc.flowless.CellPositioner.getSizedCell(CellPositioner.java:130) 
    at org.fxmisc.flowless.CellPositioner.placeStartAt(CellPositioner.java:95) 
    at org.fxmisc.flowless.Navigator.placeStartAtMayCrop(Navigator.java:183) 
    at org.fxmisc.flowless.Navigator.visit(Navigator.java:111) 
    at org.fxmisc.flowless.StartOffStart.accept(TargetPosition.java:49) 
    at org.fxmisc.flowless.Navigator.layoutChildren(Navigator.java:67) 
    at javafx.scene.Parent.layout(Parent.java:1087) 
    at org.fxmisc.flowless.VirtualFlow.layoutChildren(VirtualFlow.java:165) 
    at javafx.scene.Parent.layout(Parent.java:1087) 
    at org.fxmisc.flowless.VirtualFlow.visibleCells(VirtualFlow.java:138) 
    at com.myproject.util.javafx.codearea.SEditor.<init>(SEditor.java:659) 
    at com.myproject.util.javafx.codearea.SEditor.<init>(SEditor.java:607) 
    at com.myproject.util.javafx.codearea.SCodeArea.<init>(SCodeArea.java:122) 
    at com.myproject.meditor.SLICodeArea.<init>(SLICodeArea.java:124) 
    at com.myproject.meditor.SLICodeArea.<init>(SLICodeArea.java:114) 
    at com.myproject.meditor.SLItemCodeArea.<init>(SLICodeArea.java:106) 
    at com.myproject.meditor.SLItemCodeArea.<init>(SLICodeArea.java:103) 
    at com.myproject.meditor.SLIVCodeAreaTest.<clinit>(SLIVCodeAreaTest.java:14) 

EDIT: 2

De la trace de la pile, la partie du code qui a déclenché l'exception (SLIVCodeAreaTest.java:14) est dans la déclaration de private static final SLIVCodeArea dans la partie du code:

import static org.junit.Assert.assertTrue; 
import org.junit.Test; 

public class SLIVCodeAreaTest {  
    private static final SLIVCodeArea sEditor = new SLIVCodeArea(new SLICodeArea()) { 

     @Override protected void updateVisibleParagraphRange() {} }; 

    private static final VEditorProblemList sProblemList = 
     new VEditorProblemList(sEditor, new SimpleObjectProperty<>(), false); 

    static { sEditor.aggregatedTextChanges().setAggregationEnabled(false); } 

Edit: 3

Si je retire le mot-clé statique à partir de la partie d'initialisation ci-dessus, la pile de l'erreur devient:

Running com.myproject.meditor.SLIVCodeAreaTest 
Tests run: 17, Failures: 0, Errors: 17, Skipped: 0, Time elapsed: 1.124 sec <<< FAILURE! - in Running com.myproject.meditor.SLIVCodeAreaTest 
testRHBlock(com.myproject.meditor.SLIVCodeAreaTest) Time elapsed: 0 sec <<< ERROR! 
java.lang.RuntimeException: Internal graphics not initialized yet 
    at com.sun.glass.ui.Screen.getScreens(Screen.java:70) 
    at com.sun.glass.ui.Screen.getMainScreen(Screen.java:61) 
    at com.sun.javafx.font.PrismFontFactory.getSystemFontSize(PrismFontFactory.java:1911) 
    at com.sun.javafx.font.PrismFontLoader.getSystemFontSize(PrismFontLoader.java:240) 
    at javafx.scene.text.Font.getDefaultSystemFontSize(Font.java:71) 
    at javafx.scene.text.Font.getDefault(Font.java:86) 
    at javafx.scene.text.Text.getFont(Text.java:478) 
    at javafx.scene.text.Text.getFontInternal(Text.java:487) 
    at javafx.scene.text.Text.access$100(Text.java:95) 
    at javafx.scene.text.Text$1.getFont(Text.java:206) 
    at com.sun.javafx.text.GlyphLayout.breakRuns(GlyphLayout.java:174) 
    at com.sun.javafx.text.PrismTextLayout.buildRuns(PrismTextLayout.java:770) 
    at com.sun.javafx.text.PrismTextLayout.layout(PrismTextLayout.java:1021) 
    at com.sun.javafx.text.PrismTextLayout.ensureLayout(PrismTextLayout.java:223) 
    at com.sun.javafx.text.PrismTextLayout.getBounds(PrismTextLayout.java:246) 
    at javafx.scene.text.TextFlow.computePrefWidth(TextFlow.java:203) 
    at javafx.scene.Parent.prefWidth(Parent.java:915) 
    at javafx.scene.layout.Region.prefWidth(Region.java:1419) 
    at org.fxmisc.richtext.ParagraphBox.computePrefWidth(ParagraphBox.java:199) 
    at org.fxmisc.richtext.ParagraphBox.computeMinWidth(ParagraphBox.java:191) 
    at javafx.scene.Parent.minWidth(Parent.java:943) 
    at javafx.scene.layout.Region.minWidth(Region.java:1383) 
    at org.fxmisc.flowless.VerticalHelper.minBreadth(OrientationHelper.java:234) 
    at org.fxmisc.flowless.OrientationHelper.minBreadth(OrientationHelper.java:44) 
    at org.reactfx.collection.MappedList.get(MappedList.java:27) 
    at org.reactfx.collection.MemoizationListImpl.force(MemoizationList.java:121) 
    at org.fxmisc.flowless.SizeTracker.breadthFor(SizeTracker.java:161) 
    at org.fxmisc.flowless.CellPositioner.getSizedCell(CellPositioner.java:130) 
    at org.fxmisc.flowless.CellPositioner.placeStartAt(CellPositioner.java:95) 
    at org.fxmisc.flowless.Navigator.placeStartAtMayCrop(Navigator.java:183) 
    at org.fxmisc.flowless.Navigator.visit(Navigator.java:111) 
    at org.fxmisc.flowless.StartOffStart.accept(TargetPosition.java:49) 
    at org.fxmisc.flowless.Navigator.layoutChildren(Navigator.java:67) 
    at javafx.scene.Parent.layout(Parent.java:1087) 
    at org.fxmisc.flowless.VirtualFlow.layoutChildren(VirtualFlow.java:165) 
    at javafx.scene.Parent.layout(Parent.java:1087) 
    at org.fxmisc.flowless.VirtualFlow.visibleCells(VirtualFlow.java:138) 
    at com.myproject.util.javafx.codearea.SEditor.<init>(SEditor.java:659) 
    at com.myproject.util.javafx.codearea.SEditor.<init>(SEditor.java:607) 
    at com.myproject.util.javafx.codearea.SCodeArea.<init>(SCodeArea.java:122) 
    at com.myproject.meditor.SLICodeArea.<init>(SLICodeArea.java:124) 
    at com.myproject.meditor.SLICodeArea.<init>(SLICodeArea.java:114) 
    at com.myproject.meditor.SLICodeArea.<init>(SLICodeArea.java:106) 
    at com.myproject.meditor.SLICodeArea.<init>(SLICodeArea.java:103) 
    at com.myproject.meditor.SLIVCodeAreaTest.<init>(SLIVCodeAreaTest.java:14) 

PS: Le test a travaillé dans OSX avec et sans mot-clé statique.

Le même code fonctionne correctement sous Linux et MacOS, mais il échoue dans Windows. Est-ce que quelqu'un a une idée pourquoi?

+1

Créer et publier un [MCVE]. –

+0

Veuillez inclure la trace de la pile * entire * dans votre question. Quelle ligne de code avez-vous invoquée qui a déclenché l'exception? – VGR

+0

écrans est une variable globale ou locale? et je pense que votre méthode _staticScreaan_getScreens_ renvoie null donc votre table a des éléments null. –

Répondre

0

La combinaison de JavaFX, JUnit et java.lang.ExceptionInInitializerError est un indicateur d'occurrence supprimée de l'exception Toolkit not initialized.

Pour initialiser JavaFX, vous pouvez attendre la fin du new JFXPanel() avant de lancer le test unitaire.

Voir:

+0

Si l'exception _Toolkit non initialisée_ s'est produite, pourquoi cela ne se produit-il pas dans MacOS ou Linux? – josephino

+0

Peut dépendre de la version JRE utilisée sur MacOS, Linux ou Windows. –

+0

Qu'est-ce qu'une "occurrence supprimée" d'une exception? Qu'est-ce qui vous amène à croire que c'est un symptôme d'une application JavaFX non initialisée? Je ne vois rien dans la question SO liée qui mentionne l'une des classes dans la trace de pile de la question. – VGR

0

Selon Class ExceptionInInitializerError

public class ExceptionInInitializerError étend les signaux de LinkageError qu'une exception inattendue est survenue dans un initialiseur statique. Une exception ExceptionInInitializerError est émise pour indiquer qu'une exception s'est produite lors de l'évaluation d'un initialiseur statique ou de l'initialiseur pour une variable statique.

Parce que vous ne l'avez pas poster un Minimal, Complete, and Verifiable example. Je pense que newscreens n'est pas statique ou est initialisé par null, et vous avez essayé de transférer null variable tableau.

+0

Impossible de produire un exemple minimal complet car il y a beaucoup de dépendances, vous avez raison sur le fait qu'une exception s'est produite lors de l'évaluation d'un initialiseur statique, voir mes modifications ci-dessus – josephino