5

I have a simple EJB:

@Stateless
public class EJB {

    public void aMethod() {
        // ...
        Event event = createEvent();
        // ...
    }

    private static Event createEvent() {
        Event event = new Event();
        // ...
        return event;
    }
}

IntelliJ Ultimate shows an error because there is a static method inside an EJB.

Using JBoss EAP the EJB works fine. Does the EJB spec forbids using (private) static "helper" methods? Why? And why does it work with JBoss EAP (and most likely other application servers)?

zebra
  • 145
  • 4

1 Answers1

8

Does the EJB spec forbids using (private) static "helper" methods?

No, it does not. It does forbid the methods that make up EJBs' interface with the container to be static, whether those methods are identified by method naming patterns or by annotations. It also forbids EJBs to read or write fields that are static but not final. But it does not place a blanket prohibition on EJBs having or calling static methods.

And why does it work with JBoss EAP (and most likely othe application servers)?

Because it should. As far as I can tell, it is IntelliJ that is wrong here. I speculate that IntelliJ may be confused by the name of the particular method it is flagging, because of the appearance of "create" in it. This comes a bit close to, but does not actually match, some of the old-school method name patterns that are significant to EJB.

John Bollinger
  • 160,171
  • 8
  • 81
  • 157