I am building a JEE project using NetBeans and Maven. The project contains an EJB module, a Web module and a SE class library. As usual, the Web module has the EJB module as a dependency. They both have the class library as a dependency. The project is a modified copy of a project that has been working for years using either GlassFish or JBoss, and more recently WildFly. The original project was built and deployed using Ant. Now I am using Maven. The new (maven) project runs just fine using GlassFish but not using WildFly 10. It throws a ClassCastException in a cast statement that definitively shouldn’t fail. To try to determine the source of the problem I performed a simple test. Its result is totally bizarre. Here it is:
First I created 3 interfaces, one in the class library and one in each module. These are:
// interface at the class library
package jee2ap102.lib;
public interface I01 {
}
// interface at the EJB module
package jee2ap102.ejb;
public interface I0101 extends jee2ap102.lib.I01 {
}
// interface at the Web module
package jee2ap102.web;
public interface I010101 extends jee2ap102.ejb.I0101 {
}
Then in the Web module I created a bean and added the following method:
public String check() {
boolean b;
b = jee2ap102.lib.I01.class.isAssignableFrom(jee2ap102.ejb.I0101.class);
b = jee2ap102.lib.I01.class.isAssignableFrom(jee2ap102.web.I010101.class);
b = jee2ap102.ejb.I0101.class.isAssignableFrom(jee2ap102.web.I010101.class);
}
The three statements should return true, but only the last one does. According to this, the interface I01, located in the class library, which is the root of the hierarchy, is not assignable from any of the interfaces located outside the library (either EJB or Web module) regardless of the fact that those interfaces extend it. Consistently, an attempt to cast I0101 or I010101 to I01 will throw a ClassCastException.
I would really appreciate any help to understand and solve this problem.