-
CSR
-
Resolution: Unresolved
-
P4
-
None
-
source, behavioral
-
low
-
User might have depended on the behavior of `AccessFlag.SYNTHETIC.locations(ClassFileFormatVersion)` since it is available in release 20. The API additions have minimal risk.
-
Java API
-
SE
Summary
Add new accessor methods to AccessFlag.Location
and change behavior around AccessFlag.SYNTHETIC
.
Problem
- In the ClassFile API and other locations, we often mention about IllegalArgumentException caused by the mismatch of masks for access flags, but we never provided a way to easily detect if a mask has mismatch.
- We cannot easily get the
AccessFlag
for a location; it's easy the other way around. ACC_SYNTHETIC
was added in Java SE Platform 5.0, but currentAccessFlag.SYNTHETIC
behaves as if it was only added in 7. Keeping this inconsistent behavior increases the implementation complexity of the new methods.
Solution
Add these new methods to
AccessFlag.Location
:int flagsMask()
int flagsMask(ClassFileFormatVersion)
Set<AccessFlag> flags()
Set<AccessFlag> flags(ClassFileFormatVersion)
Change the behavior of
AccessFlag.SYNTHETIC
to apply to all of classes, inner classes, methods, and fields from releases 5.0 to 7, to ensure consistency betweenAccessFlag
andAccessFlag.Location
.
Specification
@@ -516,57 +418,129 @@ public static Set<AccessFlag> maskToAccessFlags(int mask, Location location) {
public enum Location {
/**
* Class location.
- * @jvms 4.1 The ClassFile Structure
+ *
+ * @see Class#accessFlags()
+ * @see ClassModel#flags()
+ * @jvms 4.1 The {@code ClassFile} Structure
*/
CLASS,
/**
* Field location.
+ *
+ * @see Field#accessFlags()
+ * @see FieldModel#flags()
* @jvms 4.5 Fields
*/
FIELD,
/**
* Method location.
+ *
+ * @see Executable#accessFlags()
+ * @see MethodModel#flags()
* @jvms 4.6 Methods
*/
METHOD,
/**
* Inner class location.
- * @jvms 4.7.6 The InnerClasses Attribute
+ *
+ * @see Class#accessFlags()
+ * @see InnerClassInfo#flags()
+ * @jvms 4.7.6 The {@code InnerClasses} Attribute
*/
INNER_CLASS,
/**
* Method parameter location.
- * @jvms 4.7.24 The MethodParameters Attribute
+ *
+ * @see Parameter#accessFlags()
+ * @see MethodParameterInfo#flags()
+ * @jvms 4.7.24 The {@code MethodParameters} Attribute
*/
METHOD_PARAMETER,
/**
- * Module location
- * @jvms 4.7.25 The Module Attribute
+ * Module location.
+ *
+ * @see ModuleDescriptor#accessFlags()
+ * @see ModuleAttribute#moduleFlags()
+ * @jvms 4.7.25 The {@code Module} Attribute
*/
MODULE,
/**
- * Module requires location
- * @jvms 4.7.25 The Module Attribute
+ * Module requires location.
+ *
+ * @see ModuleDescriptor.Requires#accessFlags()
+ * @see ModuleRequireInfo#requiresFlags()
+ * @jvms 4.7.25 The {@code Module} Attribute
*/
MODULE_REQUIRES,
/**
- * Module exports location
- * @jvms 4.7.25 The Module Attribute
+ * Module exports location.
+ *
+ * @see ModuleDescriptor.Exports#accessFlags()
+ * @see ModuleExportInfo#exportsFlags()
+ * @jvms 4.7.25 The {@code Module} Attribute
*/
MODULE_EXPORTS,
/**
- * Module opens location
- * @jvms 4.7.25 The Module Attribute
+ * Module opens location.
+ *
+ * @see ModuleDescriptor.Opens#accessFlags()
+ * @see ModuleOpenInfo#opensFlags()
+ * @jvms 4.7.25 The {@code Module} Attribute
*/
MODULE_OPENS;
// Repeated sets of locations used by AccessFlag constants
private static final Set<Location> EMPTY_SET = Set.of();
@@ -618,10 +590,90 @@ public enum Location {
+
+ /**
+ * {@return the union of integer masks of all access flags defined for
+ * this location in the latest class file format version} If {@code
+ * mask & ~location.flagsMask() != 0}, then a bit mask {@code mask} has
+ * one or more undefined bits set for {@code location}. This union of
+ * access flags mask may not itself be a valid flag value.
+ *
+ * @since 25
+ */
+ public int flagsMask() {
+ }
+
+ /**
+ * {@return the union of integer masks of all access flags defined for
+ * this location in the given class file format version} If {@code
+ * mask & ~location.flagsMask(cffv) != 0}, then a bit mask {@code mask}
+ * has one or more undefined bits set for {@code location} in {@code
+ * cffv}. This union of access flags mask may not itself be a valid
+ * flag value.
+ * <p>
+ * This method may return {@code 0} if the structure did not exist in
+ * the given {@code cffv}.
+ *
+ * @param cffv the class file format version
+ * @throws NullPointerException if {@code cffv} is {@code null}
+ * @since 25
+ */
+ public int flagsMask(ClassFileFormatVersion cffv) {
+ }
+
+ /**
+ * {@return all access flags defined for this location, as a set of
+ * flag enums} This set may include mutually exclusive flags.
+ *
+ * @since 25
+ */
+ public Set<AccessFlag> flags() {
+ }
+
+ /**
+ * {@return all access flags defined for this location, as a set of flag
+ * enums} This set may include mutually exclusive flags.
+ * <p>
+ * This method may return an empty set if the structure did not exist in
+ * the given {@code cffv}.
+ *
+ * @param cffv the class file format version
+ * @throws NullPointerException if {@code cffv} is {@code null}
+ * @since 25
+ */
+ public Set<AccessFlag> flags(ClassFileFormatVersion cffv) {
+ }
- csr of
-
JDK-8347471 Provide valid flags and mask in AccessFlag.Location
-
- In Progress
-