Friday, October 31, 2014

java.lang.AbstractMethodError: org.uispec4j.interception.toolkit.UISpecToolkit.getKeyboardFocusManagerPeer()Ljava/awt/peer/KeyboardFocusManagerPeer;

For one old project written in old Java swing I tried to find tool for JUnit testing. Naively I thought that there is lot of mature swing JUnit testing frameworks. Surprisingly there is no much of them. I start with uispec4j.

java.lang.AbstractMethodError: org.uispec4j.interception.toolkit.UISpecToolkit.getKeyboardFocusManagerPeer()Ljava/awt/peer/KeyboardFocusManagerPeer;
 at java.awt.KeyboardFocusManager.initPeer(Unknown Source)
 at java.awt.KeyboardFocusManager.(Unknown Source)
 at java.awt.DefaultKeyboardFocusManager.(Unknown Source)
 at java.awt.KeyboardFocusManager.getCurrentKeyboardFocusManager(Unknown Source)
 at java.awt.KeyboardFocusManager.getCurrentKeyboardFocusManager(Unknown Source)
 at javax.swing.UIManager.initialize(Unknown Source)
 at javax.swing.UIManager.maybeInitialize(Unknown Source)
 at javax.swing.UIManager.getDefaults(Unknown Source)
 at javax.swing.UIManager.put(Unknown Source)
 at org.uispec4j.interception.ui.UISpecLF.init(UISpecLF.java:11)
 at org.uispec4j.UISpec4J.init(UISpec4J.java:32)
 at org.uispec4j.UISpecTestCase.(UISpecTestCase.java:31)

Root of problem

Problem is in class org.uispec4j.interception.toolkit.UISpecToolkit which was created before java 1.7. Class UISpecToolkit implements abstract class org.uispec4j.interception.toolkit.ToolkitDelegate. ToolkitDelegate extends another abstract class SunToolkit. Class SunToolkit is root of problems. In Java 1.7 there is a new abstract method sun.awt.SunToolkit.getKeyboardFocusManagerPeer() returning KeyboardFocusManagerPeer which is not implemented in uispec4j implementing class UISpecToolkit.

Solution

First of all there is no simple solution. It's quite easy to create own version of UISpecToolkit. But it's not easy to persuade uispec4j library to user your own version of UISpecToolkit. It's because UISpecToolkit in class UISpec4J in a following way:

  private static void initToolkit() {
    try {
      Field toolkitField = Toolkit.class.getDeclaredField("toolkit");
      toolkitField.setAccessible(true);
      toolkitField.set(null, new UISpecToolkit());
    }
    catch (Exception e) {
      throw new RuntimeException("Unable to initialize toolkit for interception.", e);
    }
  }

So without new library release or some non trivial effort there is not possible to use uispec4j library at java 1.7.

Sunday, October 19, 2014

Access restriction: The constructor GraphicsConfigTemplate3D() is not accessible due to restriction on required library /System/Library/Java/Extensions/j3dcore.jar

This problem is reported by Eclipse. It's reason why project can't by compiled.

Problem is that default JRE include older 1.5 Java3D implementation which doesn't expose used GraphicsConfigTemplate3D() constructor. Solution is remove from eclipse build old 1.5 Java3D libraries and and new 1.6 to class paths.

How to configure it in eclipse is described it post Mac OS X 10.9 Mavericks how to install Java 3d.