javax:javaee-api-6.0 contains non-abstract classes with no method body

纵饮孤独 提交于 2019-12-06 13:01:05

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/20125115/javaxjavaee-api-6-0-contains-non-abstract-classes-with-no-method-body

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!