Illegal reflective access with fontawesomefx 9.0.0 (Java 9) when setting size in FXML

Issue #54 wontfix
Ben Thomas created an issue

Setting the size GlyphIcons in FXML causes illegal reflective access operation using Java 9 build 181.

WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by de.jensd.fx.glyphs.GlyphIcon (file:/Users/bwt28/.m2/repository/de/jensd/fontawesomefx-commons/9.0.0/fontawesomefx-commons-9.0.0.jar) to method javafx.css.CssParser.parseExpr(java.lang.String,java.lang.String)
WARNING: Please consider reporting this to the maintainers of de.jensd.fx.glyphs.GlyphIcon
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release

panel1.fxml:

<?import de.jensd.fx.glyphs.materialicons.MaterialIconView?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.BorderPane?>

<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8.0.65" xmlns:fx="http://javafx.com/fxml/1" fx:controller="sand.comp.Panel1Controller">
   <children>
      <BorderPane AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
         <center>
            <MaterialIconView fx:id="img" glyphName="APPS" size="100" />
         </center>
      </BorderPane>
   </children>
</AnchorPane>

TestApp.java:

public class TestApp extends Application {
    @Override
    public void start(Stage primaryStage) throws Exception {
        // load fxml
        Parent root = new FXMLLoader(getClass().getResource("panel1.fxml")).load();
        // build the scene
        Scene scene = new Scene(root);
        // set the stage, start the show
        primaryStage.setScene(scene);
        primaryStage.show();
    }
    public static void main(String[] args) {
        // launch FX application
        launch(args);
    }
}

Looks like it's caused by lines 239-241 in GlyphIcon.java

Method m = CSS_PARSER.getClass().getDeclaredMethod("parseExpr", String.class, String.class);
m.setAccessible(true);
ParsedValue parsedValue = (ParsedValue)m.invoke(CSS_PARSER, "", sizeString);

If I change one line in my FXML and remove the size="100" I do not get the warning, since GlyphIcon.convert() is called from setSize().

<MaterialIconView fx:id="img" glyphName="APPS" />

Similar to #52, but not kidding :-)

Comments (4)

  1. Jens Deters repo owner

    Well, I won't call this a BUG! By now it's a warning and my bloody workaround to get FontAwsomeFX running with Java 9 (as they made some stuff private which I am using to parse size settings in CSS)

  2. Ben Thomas reporter

    Good point, maybe improvement? Since convert() is only called from setSize(), could the body of the method use

    size = NumberFormat.getInstance().parse(sizeString);
    

    instead of the private CssParser methods? I'm dealing with similar Java 9 issues too ;-) Thanks for all the work on fontawesomefx, it's really great!

  3. Jens Deters repo owner

    Thanks for the input. Not sure this will work properly. As far as I see, the this parse() method is converting a number string into a number. GlyphIcon.convert() takes also strings like "3em" or "18px"...

  4. Log in to comment