title: IllegalAccessException while using java object in javascript
body: <p>I'm going to use WebView/WebEngine to display "logs" (i.e. chat message, game status message, ...) for simple multiplayer game.</p>
  
  <p>Here is what I wrote on javascript part.</p>
  
  <pre class="lang-js prettyprint-override"><code>function addLogMessage(o) {
      var kind = o.getMessageKindCase();
      if (kind.equals(kind.CHAT_MESSAGE)) {
          $("body").append(createChatMessage(o.getChatMessage()));
      } else (/* other cases following... */)
  }
  
  function addLogMessages(l) {
      var n = l.size();
      for (var i = 0; i &lt; n; i++) {
          addLogMessage(l.get(i));
      }
  }
  </code></pre>
  
  <p>Here is what I wrote on java part.</p>
  
  <pre class="lang-java prettyprint-override"><code>private GameStatus gameStatus;
  private WebEngine logWebEngine;
  private final ObjectProperty&lt;JSObject&gt; window = new SimpleObjectProperty&lt;&gt;(this, "window");
  
  public void initialize(URL url, ResourceBundle rb) {
      gameStatus = /* ... */;
  
      window.addListener((o, oldValue, newValue) -&gt; {
          if (newValue == null) {
              return;
          }
          // getLogMessages() will return java.util.List&lt;LogMessage&gt;
          newValue.call("addLogMessages", gameStatus.getLogMessages());
      });
  
      logWebEngine = logView.getEngine();
      logWebEngine.getLoadWorker().stateProperty().addListener((o, oldValue, newValue) -&gt; {
          if (newValue == Worker.State.SUCCEEDED) {
              window.set((JSObject) logWebEngine.executeScript("window"));
          }
      });
      logWebEngine.load(getClass().getResource("log.html").toString());
  }
  </code></pre>
  
  <p>When I called addLogMessage() from java side, it works as intended.
  However, calling addLogMessages() caused the following exception.</p>
  
  <p><code>Exception in thread "JavaFX Application Thread" java.lang.IllegalAccessException: Class sun.reflect.misc.Trampoline can not access a member of class java.util.Collections$UnmodifiableCollection with modifiers "public"</code></p>
  
  <p>It seems that <code>l.size()</code> in addLogMessages caused this exception.</p>
  
  <p>What's the reason of this exception? And, is there any solution for this issue?
  Thanks in advance.</p>