1

I am fairly new to Java EE and when I look into the compiled code (I could not find the source code for javax:javaee-api-6.0), I notice this class.

package javax.servlet;

import java.util.EventObject;

public class ServletContextEvent extends EventObject
{
  public ServletContextEvent(ServletContext paramServletContext);

  public ServletContext getServletContext();
}

However, the same class in javax:javaee-api-7.0 is this.

package javax.servlet;

import java.util.EventObject;

public class ServletContextEvent extends EventObject
{
  private static final long serialVersionUID = -7501701636134222423L;

  public ServletContextEvent(ServletContext source)
  {
    super(source);
  }

  public ServletContext getServletContext()
  {
    return (ServletContext)super.getSource();
  }
}

The also happens to ServletException in the same package (there might be more, as I didn't go through each of them).

Assuming Java Decompiler gave me what the source code looks like, from a pure java grammar point of view, I can't understand why the 6.0 classes are not abstract (or, not interfaces).

Question 1. Why are the classes in 6.0 not abstract or interfaces?

Question 2. Why is the implementation changed in 7.0? Did people realize the 6.0 version would cause trouble when you compile code with javaee-api?

The reason I ask is because I actually got compile errors when using javaee-web-api (which has similar classes as javaee-api, see this) in Intellij IDEA (12.1.4). The error looks like this:

Internal error: (java.lang.ClassFormatError) Absent Code attribute in method that is not native or abstract in class file javax/servlet/ServletContextEvent

So Question 3. Is there a way to avoid this in Intellij IDEA?

Community
  • 1
  • 1
stackoverflower
  • 3,885
  • 10
  • 47
  • 71

1 Answers1

5

Did people realize the 6.0 version would cause trouble when you compile code with javaee-api?

Yes, one of the problmes is that you cannot use those classes when running tests. See this Arquillian FAQ and Adam Bien's blog post.

Is there a way to avoid this in Intellij IDEA?

See the links above. The solution is not specific to Intellij IDEA.

rubenlop88
  • 4,171
  • 2
  • 28
  • 32
  • Thanks for answering. Seems the only solution is to use a concrete jar file that implements javaee-api, which is kind of clumsy. – stackoverflower Nov 21 '13 at 17:13
  • It's also extremely annoying when generating metamodel classes for JPA Criteria queries. Compilation fails even though the JAR is provided, and you will be deploying the application to a running Java EE server. Interestingly, javaee-api-7 works correctly. – Ian Evans Nov 22 '13 at 01:32
  • @IanEvans the javaee-api-7 does include the implementation. – rubenlop88 Nov 22 '13 at 03:16