Skip to content

OpenJDK's javac breaks on ASSERT.about(something).that(this).does(that) #2

Closed

Description

@cgruber

Due to an ambiguity (spec bug) in the JLS, there's a difference between how Eclipse and Sun's JDK on one hand compiles the following, vs. how OpenJDK's javac compiles it. Eclipse and Sun can handle this, including the type inference at play from the generic about() method.

public static final SubjectFactory<FooSubject, Foo> FOO = new FooSubjectFactory();
...
// assuming ASSERT is some AbstractVerb subclass
ASSERT.about(FOO).that(someFoo).does(somethingFooIsh);

This is the standard delegation form of extension for Truth. Unfortunately, the statement

ASSERT.about(FOO);

... itself fails to compile on OpenJDK, because it drops a piece of type inference along the way and, as it is, ends up presuming the output is Object. It works, however, if one forces the inference in assignment.

DelegatedVerb<FooSubject, Foo> FOO_ASSERT = ASSERT.about(FOO);
FOO_ASSERT.that(someFoo).does(somethingFooIsh);

This is frustrating, because it means that OpenJDK compilers will fail on the literate, convenient syntax for delegation, which means organizations that use OpenJDK internally as the only "approved" JDK can't use this syntax, as currently implemented. They can create a test-local FOO_ASSERT, or they can use extension, but the bugs logged with Oracle are circa-2009 and it looks like this is a long way out from fixed - even in Java7, since it requires JLS changes.

We can look at an alternative way to get this same effect. I'll think about how to accomplish it in a similarly convenient syntax.

Activity

  1. cgruber commented on May 22, 2014

    @cgruber
    ContributorAuthor

    Seems to pass now on OpenJDK 7 and 8, so closing this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions