void (@Nullable Window window, ID touchBarNativePeer) { long nsViewPtr = 0; if (window != null) { final ComponentPeer peer = AWTAccessor.getComponentAccessor().getPeer(window); // sun.lwawt.* isn't available outside of java.desktop => use reflection if (peer != null && peer.getClass().getName().equals("sun.lwawt.LWWindowPeer")) { final Method methodGetPlatformWindow; try { methodGetPlatformWindow = peer.getClass().getMethod("getPlatformWindow"); Object platformWindow = methodGetPlatformWindow.invoke(peer); if (platformWindow != null && platformWindow.getClass().getName().equals("sun.lwawt.macosx.CPlatformWindow")) { final Method methodGetContentView = platformWindow.getClass().getMethod("getContentView"); Object contentView = methodGetContentView.invoke(platformWindow); final Method methodGetAWTView = contentView.getClass().getMethod("getAWTView"); nsViewPtr = (long)methodGetAWTView.invoke(contentView); } else { LOG.debug("platformWindow of frame peer isn't instance of sun.lwawt.macosx.CPlatformWindow, class of platformWindow: %s", platformWindow != null ? platformWindow.getClass() : "null"); } } catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException e) { LOG.debug(e); } } else { if (peer == null) { LOG.debug("frame peer is null, window: %s", window); } else { LOG.debug("frame peer isn't instance of sun.lwawt.LWWindowPeer, class of peer: %s", peer.getClass()); } } } nstLibrary.setTouchBar(new ID(nsViewPtr), touchBarNativePeer); }