yegor256
yegor256

Reputation: 105193

What does this checkstyle message means?

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?

Upvotes: 3

Views: 1917

Answers (3)

Knubo
Knubo

Reputation: 8443

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

Upvotes: 0

Archimedes Trajano
Archimedes Trajano

Reputation: 41650

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.

Upvotes: 0

yegor256
yegor256

Reputation: 105193

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>

Upvotes: 1

Related Questions