这个 checkstyle 消息是什么意思?
这是我的代码(取自 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
问题是 checkstyle 在类路径中找不到 javax.faces.convert.ConverterException 类。将此依赖项添加到
pom.xml
解决了问题:The problem is that checkstyle can't find
javax.faces.convert.ConverterException
class in classpath. Adding this dependency topom.xml
solved the problem:您可能正在使用已删除 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.
您可以尝试排除要检查的文件:
如何禁止对文件进行所有检查在检查样式中
You could try and exclude the file for being checked:
How do I suppress all checks for a file in checkstyle