这个 checkstyle 消息是什么意思?

发布于 2024-09-13 18:53:07 字数 1383 浏览 7 评论 0原文

这是我的代码(取自 SO 问题):

package my;
import java.net.MalformedURLException;
import java.net.URL;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.ConverterException;
import javax.faces.convert.FacesConverter;
@FacesConverter(forClass = URL.class)
public class UrlConverter implements Converter {
  @Override
  public final Object getAsObject(
    final FacesContext context,
    final UIComponent component,
    final String value) throws ConverterException {
    try {
        return new URL(value);
    } catch (MalformedURLException ex) {
        throw new ConverterException(
            String.format("Cannot convert %s to URL", value),
            ex
        );
    }
  }
  @Override
  public final String getAsString(
    final FacesContext context,
    final UIComponent component,
    final Object value) {
    return ((URL)value).toString();
  }
}

这是maven-checkstyle-plugin所说的:

UrlConverter.java:0: Got an exception - java.lang.ClassFormatError: 
Absent Code attribute in method that is not native or abstract 
in class file javax/faces/convert/ConverterException

这是什么意思以及如何解决?

This is my code (taken from reply posted at SO question):

package my;
import java.net.MalformedURLException;
import java.net.URL;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.ConverterException;
import javax.faces.convert.FacesConverter;
@FacesConverter(forClass = URL.class)
public class UrlConverter implements Converter {
  @Override
  public final Object getAsObject(
    final FacesContext context,
    final UIComponent component,
    final String value) throws ConverterException {
    try {
        return new URL(value);
    } catch (MalformedURLException ex) {
        throw new ConverterException(
            String.format("Cannot convert %s to URL", value),
            ex
        );
    }
  }
  @Override
  public final String getAsString(
    final FacesContext context,
    final UIComponent component,
    final Object value) {
    return ((URL)value).toString();
  }
}

This is what maven-checkstyle-plugin says:

UrlConverter.java:0: Got an exception - java.lang.ClassFormatError: 
Absent Code attribute in method that is not native or abstract 
in class file javax/faces/convert/ConverterException

What does it mean and how to solve it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

下壹個目標 2024-09-20 18:53:07

问题是 checkstyle 在类路径中找不到 javax.faces.convert.ConverterException 类。将此依赖项添加到 pom.xml 解决了问题:

<dependency>
  <groupId>javax.faces</groupId>
  <artifactId>jsf-api</artifactId>
  <version>1.2</version>
</dependency>

The problem is that checkstyle can't find javax.faces.convert.ConverterException class in classpath. Adding this dependency to pom.xml solved the problem:

<dependency>
  <groupId>javax.faces</groupId>
  <artifactId>jsf-api</artifactId>
  <version>1.2</version>
</dependency>
她比我温柔 2024-09-20 18:53:07

您可能正在使用已删除 code 属性的 javax:javaee-api:6.0 依赖项。只要您不使用 Karaf 的 features-maven-plugin,您就可以使用 org.jboss.spec:jboss-javaee-6.0。

You are probably using the javax:javaee-api:6.0 dependency that has the code attribute removed. You can use org.jboss.spec:jboss-javaee-6.0 as long as you're not using features-maven-plugin from Karaf.

辞慾 2024-09-20 18:53:07

您可以尝试排除要检查的文件:
如何禁止对文件进行所有检查在检查样式中

You could try and exclude the file for being checked:
How do I suppress all checks for a file in checkstyle

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文