开发者

What does this checkstyle message means?

开发者 https://www.devze.com 2023-01-10 21:36 出处:网络
This is my code (taken from reply posted at SO question): package my; import java.net.MalformedURLExc开发者_如何学编程eption;

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

package my;
import java.net.MalformedURLExc开发者_如何学编程eption;
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?


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>


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号