-3

Java is Unsound https://hackernoon.com/java-is-unsound-28c84cb2b3f#.8tf5qumlb

In this article java type safety is discussed and it is compiling in some java version and not compiling in some java version .

class Unsound {
    static class Constrain<A,B extends A>{}
    static class Bind<A> {
        <B extends A>
        A upcast(Constrain<A,B> constrain , B b){
            return b;
        }
    }
    static <T,U> U coerce(T t){
        Constrain<U,? super T> constrain = null;
        Bind <U> bind = new Bind<U>();
        return bind.upcast(constrain,t);
    }
    public static void main(String ...s){
        String zero = Unsound.<Integer,String>coerce(0);
    }
}

https://raw.githubusercontent.com/namin/unsound/master/doc/unsound-oopsla16.pdf

So if they say this boils down to a null-pointer bug. But unlike most null-pointer bugs

So just not able to understand its compilation or non compilation on different IDE

An open bug is also there related to it https://bugs.openjdk.java.net/browse/JDK-8054941

and eclipse also https://bugs.eclipse.org/bugs/show_bug.cgi?id=510900

luk2302
  • 46,204
  • 19
  • 86
  • 119
SarthAk
  • 1,370
  • 3
  • 11
  • 24

1 Answers1

0

The answer to your question is in the article you've referenced.

If your compiler doesn’t type-check our example, I have news for you. No, your compiler isn’t catching the bug. In fact, your compiler itself has a bug. Your compiler is broken. The Java specification says this example should type check and compile.

Now just pair this with the fact that different IDE may use different compilers (Eclipse uses it's own, IntelliJ uses javac by default, but it is configurable, etc.), and you've got your suspect. :)

korolar
  • 1,140
  • 1
  • 11
  • 19