JDK-7051206 : JSR 292 method name SwitchPoint.isValid is misleading to unwary users; should be hasBeenInvalidated
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.lang.invoke
  • Affected Version: 7
  • Priority: P3
  • Status: Closed
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2011-06-03
  • Updated: 2017-05-16
  • Resolved: 2011-07-18
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 7
7 b145Fixed
Related Reports
Relates :  
Description
Proposed action:  The query method SwitchPoint.isValid was introduced in 7032323 after a vote by the JSR 292 Expert Group.  Subsequently, one member (IBM) has asked that, if the API is not removed, it be renamed to SwitchPoint.hasBeenInvalidated, with an inverted boolean sense.  (I.e., a valid switchpoint reports hasBeenInvalidated=false.)

This is a reasonable request from IBM, strongly presented.

From: Daniel Heidinga <###@###.###>
Date: June 2, 2011 2:25:40 PM PDT
To: John Rose <###@###.###>
Subject: SwitchPoint#isValid() is the wrong api

Hi John,

As we discussed earlier, SwitchPoint#isValid() is the wrong api. It leads users to make decisions based on the transient state of the SwitchPoint, rather than its terminal state. The only actionable information the SwitchPoint can provide is whether it has already been invalidated. The API in question shouldn't be 'isValid()', rather it should be 'hasBeenInvalidated()'.

Providing an isValid() query will encourage users to introduce bugs and race conditions into their programs. Regardless of how many warnings we put in the javadoc for this method, most users will find 'isValid()' from their IDE's code completion and never read the javadoc until they get bitten by the race conditions due to its use. Let's not encourage our users to create bugs.

Ideally, I'd like to see this API removed. If it can't be removed, at least rename it to 'hasBeenInvalidated()' so that the query guides users to the only safe use.

Regards,
--Dan

Comments
EVALUATION See main CR
04-06-2011

EVALUATION Ok.
03-06-2011