-
Bug
-
Resolution: Fixed
-
P3
-
5.0
-
b55
-
x86
-
windows_xp
-
Verified
FULL PRODUCT VERSION :
java version "1.5.0"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-b64)
Java HotSpot(TM) Client VM (build 1.5.0-b64, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows XP [Version 5.1.2600]
A DESCRIPTION OF THE PROBLEM :
The following source code compiles although it should be rejected because the anonymous inner class doesn't implement the interface Test231i and therefore it is illegal to cast the this pointer of the anonymous inner class to the interface:
class Test231 implements Test231i
{
void foo()
{
new Object()
{
Test231i bar()
{
return (Test231i)this;
}
};
}
}
interface Test231i
{
}
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Compile the example given in the description with javac.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Compilation should fail with an error message.
ACTUAL -
No errors are reported by javac.
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
class Test231 implements Test231i
{
void foo()
{
new Object()
{
Test231i bar()
{
return (Test231i)this;
}
};
}
}
interface Test231i
{
}
---------- END SOURCE ----------
###@###.### 2005-1-21 06:52:01 GMT
java version "1.5.0"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-b64)
Java HotSpot(TM) Client VM (build 1.5.0-b64, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows XP [Version 5.1.2600]
A DESCRIPTION OF THE PROBLEM :
The following source code compiles although it should be rejected because the anonymous inner class doesn't implement the interface Test231i and therefore it is illegal to cast the this pointer of the anonymous inner class to the interface:
class Test231 implements Test231i
{
void foo()
{
new Object()
{
Test231i bar()
{
return (Test231i)this;
}
};
}
}
interface Test231i
{
}
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Compile the example given in the description with javac.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Compilation should fail with an error message.
ACTUAL -
No errors are reported by javac.
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
class Test231 implements Test231i
{
void foo()
{
new Object()
{
Test231i bar()
{
return (Test231i)this;
}
};
}
}
interface Test231i
{
}
---------- END SOURCE ----------
###@###.### 2005-1-21 06:52:01 GMT
- relates to
-
JDK-6520152 ACC_FINAL flag for anonymous classes shouldn't be set
- Closed
-
JDK-8161009 15.9.5: Anonymous classes aren't actually 'final'
- Closed
-
JDK-8161013 Never treat anonymous classes as 'final'
- Closed
-
JDK-4916620 legal cast is rejected
- Closed
-
JDK-8034044 Class.getModifiers() returns "static" for anonymous classes
- Closed
-
JDK-7064370 Anonymous inner class in incorrectly non-public
- Closed
(1 relates to)