J++ Bugs

I've noticed four bugs that users should be aware of:

  1. J++ does not carry over unimplemented abstract methods inherited from one abstract class to a derived abstract class.  The following code example compiles without errors, even though it should not:
    abstract class A
    {
        abstract int a();
        abstract int b();
        abstract int c();
    }
    abstract class B extends A
    {
        int a()
        {
            return 2;
        }
        // The problem is right here: while methods b() and c() should be
        // "inherited abstractly," they are not.  Therefore a class that
        // extends B does not have to implement b() and c().
    }
    class C extends B
    {
        int b()
        {
            return 4;
        }
        // This class should not compile because method c() is not implemented.
        // However, because of the J++ bug, it does.
    }

    Workarounds:

  2. You cannot hold a final reference to an instance of an internal class, unless that reference is null.  The following code example illustrates:
    class A
    {
        final B b = new B();
        // This does compile, but a build on the whole project will fail (with the infamous
        // "Internal Compiler Error") because we marked variable b to be final.  I guess the
        // compiler has a hard time deciding how to build the constructor for class A because
        // it has to create the instance of B before the instance of A.
        class B
        {
            int a()
            {
                return -2;
            }
        }
    }

    Workarounds:

  3. Apparently you can assign to a final String reference using the += operator, as below:
  4. final String s = "abc";
    s += "def";

    The JDK compiler rejects this as a syntax error, but J++ compiles it without errors.

  5. The compiler thinks an abstract method has not been implemented if a class has a member has the same name as an abstract method it implemented.  For example, the following code does not compile, even though it should:
    abstract class a
    {
        abstract int f();
    }
    class b extends a
    {
        int f()
        {
            return 4;
        }
        private boolean f; // Because we declared this field, J++ thinks
                           // we didn't implement f()
    }

    Workarounds:

  6. You cannot nest anonymous classes, although in the JDK compiler you can.

  7. Jonas Gifford, January 14, 2004