5

I have a class file and when I'm on the website the following message comes:

Incompatible magic value 1768713317 in class file "spectrum".

What does this magic value mean? Please help :)

Akash KC
  • 16,057
  • 6
  • 39
  • 59
narf
  • 53
  • 4

2 Answers2

10

The first four bytes of .class file (compiled Java binary) should be 0xCAFEBABE - so called magic value.

In your case these are 1768713317 or 0x696C6C65 or "ille" (ille...gal?) in ASCII. Most likely some JVM tries to open a file thinking that this is bytecode, while it is actually a text file. Maybe class was suppose to be downloaded but the server returns some error instead?

Tomasz Nurkiewicz
  • 334,321
  • 69
  • 703
  • 674
  • Sorry for that question, but what does ille means? Where does I have to add the magic value? – narf Sep 01 '12 at 20:18
  • @narf: It means that some JVM tries to load a class that is not really compiled Java, but probably some text file. If you take JPG image and change its extension to .EXE, most likely you'll get some sort of error as well. Sorry, but your question is too vague, can you provide more details? – Tomasz Nurkiewicz Sep 01 '12 at 20:39
5

Magic number is the first 4 bytes in each compiled Java class. This is the structure of a compiled Java class:

ClassFile {
    u4             magic;
    u2             minor_version;
    u2             major_version;
    u2             constant_pool_count;
    cp_info        constant_pool[constant_pool_count-1];
    u2             access_flags;
    u2             this_class;
    u2             super_class;
    u2             interfaces_count;
    u2             interfaces[interfaces_count];
    u2             fields_count;
    field_info     fields[fields_count];
    u2             methods_count;
    method_info    methods[methods_count];
    u2             attributes_count;
    attribute_info attributes[attributes_count];
}

'magic' should always be equal to: 0xCAFEBABE. It tells the JVM: "Hey you! I'm a Java class, you can execute my code!". When JVM reads a file and the magic number is not valid it won't execute it.

Robert Harvey
  • 178,213
  • 47
  • 333
  • 501
Adam Sznajder
  • 9,108
  • 4
  • 39
  • 60
  • That's not the output. This structure was taken from JVM specification: http://docs.oracle.com/javase/specs/jvms/se7/html/jvms-4.html#jvms-4.1 – Adam Sznajder Sep 01 '12 at 19:55