Java - What Causes ClassFormatError?

Go To StackoverFlow.com

1

When running program from Eclipse it works fine.

When running it outside of Eclipse I get this:

 java.lang.ClassFormatError: Duplicate method name&signature in class file [Class Name]

The class in question implements from an interface, and the program has several other classes that extend from the class mentioned in the error.

What causes this and how is it fixed?

2012-04-05 02:05
by WildBamaBoy
At a guess I'd say you've got two methods with the same name & signature in the class - joshuahealy 2012-04-05 02:07
Can you post the class code? It might help - Chetter Hummin 2012-04-05 02:07
@appclay Shouldn't Eclipse detect that - Chetter Hummin 2012-04-05 02:07
The class is a bit large...894 lines. Should I post it on here? And it doesn't have duplicate methods, Eclipse DOES detect that and it won't compile if it does - WildBamaBoy 2012-04-05 02:09
@AmitBhargava I would've thought so, and I would've thought compiling would've produced the error too - joshuahealy 2012-04-05 02:10
You might check that the code you are running from outside Eclipse is exactly the code you think it should be. It could be a simple copy/paste error or something like that.. if it were me I would take the class file that is giving me the issue outside Eclipse, decompile it with cavaj or some other tool, and check for a duplicate method - user506069 2012-04-05 02:11


2

Thrown when the Java Virtual Machine attempts to read a class file and determines that the file is malformed or otherwise cannot be interpreted as a class file.

http://docs.oracle.com/javase/7/docs/api/java/lang/ClassFormatError.html

The Javadocs are your friend.

2012-04-05 02:10
by Sam Rueby
WTH? What in the world would make it think that it's not a class file - WildBamaBoy 2012-04-05 02:13
It could be something as stupid as the file encoding. You said "while running it outside of Eclipse". Did you re-save the file from another text editor that switched the file encoding on you? It probably needs to be UTF8 - Sam Rueby 2012-04-05 02:15
I didn't...it appears that there's a duplicate method being added. The two duplicates are from the interface its implementing from. But the methods are totally different - WildBamaBoy 2012-04-05 02:20
can you show us the signature of the dupplicate method - NoName 2012-04-05 02:24
Nevermind, they aren't duplicate. There's "a" and "a_", I didn't notice the underscore - WildBamaBoy 2012-04-05 02:31
@WildBamaBoy - assuming that those aren't generated methods ... you really, really should be sticking to the Java conventions. An underscore character anywhere in a method name violates the Sun / Oracle conventions, and a trailing underscore is just asking for trouble. Perhaps you should get your co-workers to review your code - Stephen C 2012-04-05 04:35


2

I had the same issue. As for me, root cause was that aspectj plugin compiles sources two times. Aspect class leaves in 'service' module and compiles with aspectJ plugin. And then it comes already compile into top-level 'web' module as dependency and complies once again (because 'service' module was as 'weaveDependency' in 'web' module's aspectJ plugin config). Solution: I've replaced next configuration in 'web' module

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>aspectj-maven-plugin</artifactId>
    <version>1.5</version>
    <configuration>
        <weaveDependencies>
            <weaveDependency>
                <groupId>com.taxi.core</groupId>
                <artifactId>service</artifactId>
            </weaveDependency>
        </weaveDependencies>
    </configuration>

with

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>aspectj-maven-plugin</artifactId>
    <version>1.5</version>
    <configuration>
        <aspectLibraries>
            <aspectLibrary>
                <groupId>com.taxi.core</groupId>
                <artifactId>service</artifactId>
            </aspectLibrary>
        </aspectLibraries>
    </configuration>

2015-01-15 14:37
by Vladimir Filipchenko


0

Googled and Found that Disabling "Deploy on save" may help to overcome the problem. Try on test platform and go for production!

2013-01-10 13:28
by AVA
Ads