Bug 24558

Summary: compiler error, method declaration in interface -> NullPointerException
Product: [Eclipse Project] JDT Reporter: Jari Kujansuu <Jari.Kujansuu>
Component: CoreAssignee: Philipe Mulet <philippe_mulet>
Status: RESOLVED WORKSFORME QA Contact:
Severity: major    
Priority: P3    
Version: 2.0.1   
Target Milestone: 2.1 M2   
Hardware: PC   
OS: Windows XP   
Whiteboard:
Attachments:
Description Flags
JAR containing class and java files for test case that showed error. none

Description Jari Kujansuu CLA 2002-10-09 06:59:35 EDT
With Compiler/JDK Compliance/Compiler compliance level 1.4 get 
NullPointerException in following system. On any other level everything works 
fine.

Interface A { int hashCode(); }
Interface B extends A {}
Class C implements B {
 int hashCode() { return super.hashCode(); }
}

Then I create object of class C and call hashCode() on it when object is 
typecasted to different classes.

Object -> OK
A -> OK
B -> NullPointerException
C -> OK

Also tested exatly same with test() method declared in A, everything was OK. 
Then same with toString -> in case B again got NullPointerException.

I have classes that show this error and can post them if requested.
Comment 1 Philipe Mulet CLA 2002-10-09 09:20:34 EDT
I cannot reproduce with the following test case:

interface A {
	int hashCode();
}

interface B extends A {
}

class C implements B {
	public int hashCode(){
		return super.hashCode();
	}
}

public class Test {
	public static void main(String[] arguments) {
		C c = new C();
		System.out.println("((A)c).hashCode() : "+ ((A)c).hashCode());
		System.out.println("((B)c).hashCode() : "+ ((B)c).hashCode());
		System.out.println("((C)c).hashCode() : "+ ((C)c).hashCode());
	}
}

Can you provide exact test case ? It seems to depend on the fact that an Object 
method is involved, but I need exact case.
Comment 2 Jari Kujansuu CLA 2002-10-09 12:31:23 EDT
Created attachment 2138 [details]
JAR containing class and java files for test case that showed error.
Comment 3 Philipe Mulet CLA 2002-10-10 06:48:37 EDT
Tried your test case, works fine either in latest 2.1 integration build or 
2.0.2:

Object: 16032330
Object.toString(): C.toString()
Interface A.test(): 16032330
Interface A.toString(): C.toString()
Interface A.hashCode(): 16032330
Interface B.test(): 16032330
Interface B.hashCode(): 16032330
Interface B.toString(): C.toString()
Class C.test():16032330
Class C.hashCode():16032330
Class C.toString(): C.toString()
Comment 4 Philipe Mulet CLA 2002-10-10 06:52:22 EDT
Couldn't reproduce it either on 2.0.1.

Could this be a VM bug ? Which JRE are you using. I am using Sun JDK 1.4.1 b18 
(b14 had numerous issues on this front).
Comment 5 Jari Kujansuu CLA 2002-10-10 08:28:33 EDT
Installed Sun's SDK 1.4.1 and error was gone. 

When compiling with Eclipse and running 1.4.0 (01 and 02) it doesn't work. 
When compiling with normal 1.4.0 everything works. When compiling with Eclipse 
and running 1.4.1 it works.
Comment 6 Philipe Mulet CLA 2002-10-11 06:42:40 EDT
Ok, then closing as VM bug.