JDK-8043188 : 12.4.1: Trigger interface initialization on default/static method invocation
  • Type: Bug
  • Component: specification
  • Sub-Component: language
  • Affected Version: 8
  • Priority: P4
  • Status: Closed
  • Resolution: Fixed
  • Submitted: 2014-05-14
  • Updated: 2017-02-17
  • Resolved: 2015-02-16
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 8
8u40Fixed
Related Reports
Duplicate :  
Relates :  
Relates :  
Description
If a static method of an interface is invoked, the interface's static fields should be initialized.  "T is a class and a static method declared by T is invoked" should no longer be restricted to classes.

If a default method of an interface is invoked, it should also cause the static fields of the interface to be initialized.  This is probably best handled with a new rule.
Comments
Rather than try to define when an instance of an interface is created, I prefer the following specification technique: i) specify the explicit triggers that cause a specific named class/interface to be initialized, then ii) indicate that initialization of said class/interface is itself a trigger for initialization of superclasses and/or superinterfaces. The detailed initialization procedure in 12.4.2 has the details, of course.
25-11-2014

A note should be added to allow additional flexibility in 12.4.1 and 12.4.2 for compilers that generate synthetic default methods. When we speak of "declares a default method", ANY interface may have this property (in this context), depending on the implementation's decisions about generating synthetic code. In other words, when an object is instantiated that directly or indirectly implements an uninitialized interface, that MUST trigger initialization of the interface if the interface declares a default method at the language level, and MAY trigger initialization of the interface otherwise.
09-10-2014

The term "instance of T" where T is an interface needs clarity. Unless we make an additional distinction between modes of initialization (new-instance-time vs. touch-static-time), we should define that "x is an instance of T" if the expression "x instanceof T" would return true, for T an interface. Otherwise, the unwary reader might think that only the immediate supers of x's type were in question.
17-09-2014

The details in 12.4.2 also need to be clarified (in particular, Step 7), consistent with JDK-8043190.
15-09-2014

Modified behavior for default methods: The suggestion to trigger initialization of an interface when a default method is "invoked" (should be interpreted as "selected for invocation") is impractical to implement. Instead, the rule should be: "T is a class ***or an interface that declares a default method*** and an instance of T is created." (This is a change from the current unspecified behavior of Hotspot, which initializes the interface when it declares _or inherits_ a default method.)
15-09-2014