robotframework / JavalibCore

Base for implementing Java test libraries to be used with Robot Framework
Other
42 stars 25 forks source link

Calling dynamic method 'getKeywordNames' failed: ExceptionInInitializerError when multiple keyword pattern is used #16

Closed alejandro-serrano closed 9 years ago

alejandro-serrano commented 9 years ago

Hello,

We are having the problem described in the title of this issue when we are exposing keywords from a JavaLibraryA in a JavaLibraryB using the multiple keyword patterns approach.

We are encapsulating JavaLibraryA in JavaLibraryB as follows:

public class JavaLibraryB extends AnnotationLibrary { private AnnotationLibrary libA = new JavaLibraryA();

// If we use the approach below we get the ExceptionInInitializerError when we call super.getKeywordNames method (look for the comment "Here is where we get the failure!!!!!") //
// Notice in your example in the documentation you are declaring keywordPatterns as non-static, it must be declared as static if you want to use it in the constructor. // static List keywordPatterns = new ArrayList() {{ // add("com/acme//keyword//*.class"); // add("org/some/other/place/**.class"); // }}; // public JavaLibraryB() { // super(keywordPatterns); // }

// Even trying something like this, it fails... // public JavaLibraryB(){ // super(Arrays.asList("com/acme//keyword//*.class", "org/some/other/place/**.class")); // } //

// If we use this approach, it works fine but we cannot add multiple keyword patterns
public JavaLibraryB() {
    super("com/acme/**/keyword/**/*.class");
}

@Override
public String[] getKeywordNames() {
    String[] mine = super.getKeywordNames(); // --------> Here is where we get the failure!!!!!
    return ArrayUtils.addAll(mine, libA.getKeywordNames()); // using Apache Commons Lang
}

@Override
public Object runKeyword(String name, Object[] args) {
    if (Arrays.asList(libA.getKeywordNames()).contains(name)) {
        return libA.runKeyword(name, args);
    }
    return super.runKeyword(name, args);
}

// more overrides go here . . .

Any help would be appreciated. Thanks. Alejandro.

alejandro-serrano commented 9 years ago

After investigating the issue one of our Team members discovered that it was an issue in our library.

Thank you, Alejandro.