Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion make/modules/java.base/Java.gmk
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
# new warning is added to javac, it can be temporarily added to the
# disabled warnings list.
#
DISABLED_WARNINGS_java += initialization
# DISABLED_WARNINGS_java +=

DOCLINT += -Xdoclint:all/protected \
'-Xdoclint/package:java.*,javax.*'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,12 +251,6 @@ public enum LintCategory {
*/
INCUBATING("incubating", Property.NO_ANNOTATION_SUPPRESSION, Property.ENABLED_BY_DEFAULT),

/**
* Warn about code in identity classes that wouldn't be allowed in early
* construction due to a this dependency.
*/
INITIALIZATION("initialization"),

/**
* Warn about compiler possible lossy conversions.
*/
Expand Down
15 changes: 4 additions & 11 deletions src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java
Original file line number Diff line number Diff line change
Expand Up @@ -1196,7 +1196,6 @@ public void visitMethodDef(JCMethodDecl tree) {
// Add an implicit super() call unless an explicit call to
// super(...) or this(...) is given
// or we are compiling class java.lang.Object.
boolean addedSuperInIdentityClass = false;
if (isConstructor && owner.type != syms.objectType) {
if (!TreeInfo.hasAnyConstructorCall(tree)) {
JCStatement supCall = make.at(tree.body.pos).Exec(make.Apply(List.nil(),
Expand All @@ -1205,7 +1204,6 @@ public void visitMethodDef(JCMethodDecl tree) {
tree.body.stats = tree.body.stats.append(supCall);
} else {
tree.body.stats = tree.body.stats.prepend(supCall);
addedSuperInIdentityClass = true;
}
} else if ((env.enclClass.sym.flags() & ENUM) != 0 &&
(tree.mods.flags & GENERATEDCONSTR) == 0 &&
Expand Down Expand Up @@ -1243,7 +1241,6 @@ public void visitMethodDef(JCMethodDecl tree) {
if (isConstructor && owner.type != syms.objectType) {
boolean hasThisConstructorCall = TreeInfo.hasConstructorCall(tree, names._this);
localEnv.info.earlyContext = EarlyConstructionContext.of(owner,
addedSuperInIdentityClass && allowValueClasses,
hasThisConstructorCall && allowValueClasses);
}

Expand Down Expand Up @@ -1323,10 +1320,9 @@ public void visitVarDef(JCVariableDecl tree) {
initEnv.info.enclVar = v;
EarlyConstructionContext previousEarlyConstruction = initEnv.info.earlyContext;
try {
if (v.owner.kind == TYP && !v.isStatic() && allowValueClasses) {
if (v.isStrictInstance() && allowValueClasses) {
// instance strict field init occur in early construction context
initEnv.info.earlyContext = EarlyConstructionContext.of((ClassSymbol)v.owner,
!v.isStrict(), false);
initEnv.info.earlyContext = EarlyConstructionContext.of((ClassSymbol)v.owner, false);
}
attribExpr(tree.init, initEnv, v.type);
if (tree.isImplicitlyTyped()) {
Expand Down Expand Up @@ -2588,11 +2584,8 @@ public void visitApply(JCMethodInvocation tree) {
argtypes = argtypesBuf.toList();
typeargtypes = attribTypes(tree.typeargs, localEnv);

// Done with this()/super() parameters.
if (!env.info.earlyContext.onlyWarnings()) {
// End of constructor prologue (but only if no initialization warnings are needed)
env.info.earlyContext = EarlyConstructionContext.NONE;
}
// End of constructor prologue. Done with this()/super() parameters.
env.info.earlyContext = EarlyConstructionContext.NONE;

// Variable `site' points to the class in which the called
// constructor is defined.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,23 +33,21 @@
* references are disallowed when inside a lambda
*/
record EarlyConstructionContext(ClassSymbol owner,
boolean onlyWarnings,
boolean restricted,
boolean ctorPrologue) {

/**
* Dummy context. Used when not in early construction context
*/
static final EarlyConstructionContext NONE =
new EarlyConstructionContext(null, false, false, false);
new EarlyConstructionContext(null, false, false);

/**
* Create a root early context
*/
static EarlyConstructionContext of(ClassSymbol owner,
boolean onlyWarnings,
boolean restricted) {
return new EarlyConstructionContext(owner, onlyWarnings, restricted, !onlyWarnings);
return new EarlyConstructionContext(owner, restricted, true);
}

/**
Expand All @@ -60,7 +58,7 @@ EarlyConstructionContext nested(boolean isClass) {
if (this == NONE) {
return this;
}
return new EarlyConstructionContext(owner, onlyWarnings, true,
return new EarlyConstructionContext(owner, true,
!isClass && ctorPrologue);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -297,9 +297,8 @@ public void visitVarDef(JCVariableDecl tree) {
Env<AttrContext> initEnv = getInitEnv(tree, env);
initEnv.info.enclVar = v;
initEnv = initEnv(tree, initEnv);
if (v.owner.kind == TYP && !v.isStatic() && allowValueClasses) {
initEnv.info.earlyContext = EarlyConstructionContext.of((ClassSymbol)v.owner,
!v.isStrict(), false);
if (v.isStrictInstance() && allowValueClasses) {
initEnv.info.earlyContext = EarlyConstructionContext.of((ClassSymbol)v.owner, false);
}
v.setLazyConstValue(initEnv(tree, initEnv), env, attr, tree);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
import com.sun.tools.javac.main.Option;
import com.sun.tools.javac.resources.CompilerProperties.Errors;
import com.sun.tools.javac.resources.CompilerProperties.Fragments;
import com.sun.tools.javac.resources.CompilerProperties.LintWarnings;
import com.sun.tools.javac.resources.CompilerProperties.Warnings;
import com.sun.tools.javac.tree.*;
import com.sun.tools.javac.tree.JCTree.*;
Expand Down Expand Up @@ -2048,7 +2047,7 @@ Symbol findFun(Env<AttrContext> env, Name name,
EarlyConstructionContext context = env1.info.earlyContext;
if (env1.enclClass.sym == context.owner()) {
Assert.check(env.tree.hasTag(APPLY));
return earlyRefResult(((JCMethodInvocation)env.tree).meth, context, sym, false);
return new RefBeforeCtorCalledError(sym, false);
}
}
}
Expand Down Expand Up @@ -3840,7 +3839,7 @@ Symbol findSelfContaining(DiagnosticPosition pos,
return new StaticError(sym);
} else if (env1.enclClass.sym == env1.info.earlyContext.owner()) {
// early construction context, stop search
return earlyRefResult(pos, env1.info.earlyContext, sym, false);
return new RefBeforeCtorCalledError(sym, false);
} else {
// found it
return sym;
Expand Down Expand Up @@ -3907,7 +3906,7 @@ Symbol resolveSelf(DiagnosticPosition pos,
EarlyConstructionContext context = env1.info.earlyContext;
if (sym.owner == context.owner() &&
!isReceiverParameter(env, tree)) {
sym = earlyRefResult(pos, context, sym, false);
sym = new RefBeforeCtorCalledError(sym, false);
}
}
return sym;
Expand All @@ -3926,7 +3925,7 @@ Symbol resolveSelf(DiagnosticPosition pos,
types.asSuper(env.enclClass.type, c), env.enclClass.sym);
EarlyConstructionContext context = env.info.earlyContext;
if (context != EarlyConstructionContext.NONE) {
sym = earlyRefResult(pos, context, sym, false);
sym = new RefBeforeCtorCalledError(sym, false);
}
env.info.defaultSuperCallSite = t;
return sym;
Expand Down Expand Up @@ -3990,7 +3989,7 @@ private Symbol checkEarlyFieldRef(DiagnosticPosition pos, Env<AttrContext> env,
} else {
boolean isEarlyWrite = writeOnlyTarget &&
field.owner == context.owner();
return earlyRefResult(pos, context, field, isEarlyWrite);
return new RefBeforeCtorCalledError(field, isEarlyWrite);
}
}

Expand Down Expand Up @@ -4039,42 +4038,28 @@ private boolean isSimpleEarlyFieldRefAllowed(DiagnosticPosition pos,
return false;
}
if ((field.flags_field & HASINIT) != 0 &&
!field.isStrict() &&
!context.onlyWarnings()) {
!field.isStrict()) {
// Either the declaration of the named variable has no initializer,
// or C is a value class (8.1.1.5). Plus, if warnings are enabled, treat
// the variable as strict -- as if it was declared in a value class.
// To preserve legacy behavior, bad final field writes are never reported as early access.
// or C is a value class (8.1.1.5). To preserve legacy behavior,
// bad final field writes are never reported as early access.
return writeOnlyTarget && field.isFinal();
}
// At this point we have seen a legal early ref
if (!context.onlyWarnings()) {
if (writeOnlyTarget) {
// Write early ref, this is allowed with flexible constructor bodies
preview.checkSourceLevel(pos, Feature.FLEXIBLE_CONSTRUCTORS);
} else {
// Read early ref, this is only allowed under JEP 401, and requires special codegen support
preview.checkSourceLevel(pos, Feature.VALUE_CLASSES);
if (context.ctorPrologue() && env.enclMethod != null) {
// Track the early read for codegen
localProxyVarsGen.addFieldReadInPrologue(env.enclMethod, field);
}
if (writeOnlyTarget) {
// Write early ref, this is allowed with flexible constructor bodies
preview.checkSourceLevel(pos, Feature.FLEXIBLE_CONSTRUCTORS);
} else {
// Read early ref, this is only allowed under JEP 401, and requires special codegen support
preview.checkSourceLevel(pos, Feature.VALUE_CLASSES);
if (context.ctorPrologue() && env.enclMethod != null) {
// Track the early read for codegen
localProxyVarsGen.addFieldReadInPrologue(env.enclMethod, field);
}
}
return true;
}

/** Return a symbol modeling the early access, and warn if necessary */
private Symbol earlyRefResult(DiagnosticPosition pos, EarlyConstructionContext context, Symbol sym,
boolean isEarlyWrite) {
if (context.onlyWarnings()) {
log.warning(pos, LintWarnings.WouldNotBeAllowedInPrologue(sym));
return sym;
}
return new RefBeforeCtorCalledError(sym, isEarlyWrite);
}

/* ***************************************************************************
/* ***************************************************************************
* ResolveError classes, indicating error situations when accessing symbols
****************************************************************************/

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4393,11 +4393,6 @@ compiler.warn.attempt.to.synchronize.on.instance.of.value.based.class=\
compiler.warn.attempt.to.use.value.based.where.identity.expected=\
use of a value-based class with an operation that expects reliable identity

# 0: symbol or name
# lint: initialization
compiler.warn.would.not.be.allowed.in.prologue=\
reference to {0} would not be allowed in the prologue phase

# 0: type
compiler.err.enclosing.class.type.non.denotable=\
enclosing class type: {0}\n\
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,10 +232,6 @@ javac.opt.Xlint.desc.finally=\
javac.opt.Xlint.desc.incubating=\
Warn about use of incubating modules.

javac.opt.Xlint.desc.initialization=\
Warn about code in identity classes that wouldn''t be allowed in early\n\
\ construction due to a this dependency.

javac.opt.Xlint.desc.lossy-conversions=\
Warn about possible lossy conversions in compound assignment and bit shift operations.

Expand Down
2 changes: 0 additions & 2 deletions src/jdk.compiler/share/classes/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,6 @@
* the next
* <tr><th scope="row">{@code finally} <td>{@code finally} clauses that do not terminate normally
* <tr><th scope="row">{@code identity} <td>use of a value-based class where an identity class is expected
* <tr><th scope="row">{@code initialization} <td>code in identity classes that wouldn't be allowed in early
* construction due to a {@code this} dependency.
* <tr><th scope="row">{@code lossy-conversions} <td>possible lossy conversions in compound assignments or bit shifts
* (more than \u00B131 bits for integers or \u00B163 bits for longs)
* <tr><th scope="row">{@code missing-explicit-ctor} <td>missing explicit constructors in public and protected classes
Expand Down
3 changes: 0 additions & 3 deletions src/jdk.compiler/share/man/javac.md
Original file line number Diff line number Diff line change
Expand Up @@ -610,9 +610,6 @@ file system locations may be directories, JAR files or JMOD files.

- `incubating`: Warns about the use of incubating modules.

- `initialization`: Warns about code in identity classes that wouldn't be
allowed in early construction due to a `this` dependency.

- `lossy-conversions`: Warns about possible lossy conversions
in compound assignment and bit shift operations.

Expand Down
2 changes: 0 additions & 2 deletions test/langtools/tools/javac/SuperInit/EarlyAssignments.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
* jdk.compiler/com.sun.tools.javac.util
* @enablePreview
* @compile/fail/ref=EarlyAssignments.out -XDrawDiagnostics EarlyAssignments.java
* @build SuperCallRemover
* @compile/fail/ref=EarlyAssignmentsWarnings.out -Xlint:initialization -Werror -XDrawDiagnostics -processor SuperCallRemover EarlyAssignments.java
*/
public class EarlyAssignments {

Expand Down
40 changes: 20 additions & 20 deletions test/langtools/tools/javac/SuperInit/EarlyAssignments.out
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
EarlyAssignments.java:34:26: compiler.err.cant.ref.before.ctor.called: x
EarlyAssignments.java:35:21: compiler.err.cant.ref.before.ctor.called: x
EarlyAssignments.java:36:26: compiler.err.cant.ref.before.ctor.called: x
EarlyAssignments.java:37:21: compiler.err.cant.ref.before.ctor.called: x
EarlyAssignments.java:38:26: compiler.err.cant.ref.before.ctor.called: x
EarlyAssignments.java:39:34: compiler.err.cant.ref.before.ctor.called: x
EarlyAssignments.java:41:36: compiler.err.cant.ref.before.ctor.called: this
EarlyAssignments.java:45:17: compiler.err.cant.ref.before.ctor.called: x
EarlyAssignments.java:49:21: compiler.err.cant.ref.before.ctor.called: x
EarlyAssignments.java:53:22: compiler.err.cant.ref.before.ctor.called: x
EarlyAssignments.java:71:13: compiler.err.cant.ref.before.ctor.called: x
EarlyAssignments.java:72:17: compiler.err.cant.ref.before.ctor.called: x
EarlyAssignments.java:73:25: compiler.err.cant.ref.before.ctor.called: this
EarlyAssignments.java:74:31: compiler.err.cant.ref.before.ctor.called: this
EarlyAssignments.java:124:17: compiler.err.cant.ref.before.ctor.called: x
EarlyAssignments.java:129:22: compiler.err.cant.ref.before.ctor.called: x
EarlyAssignments.java:134:29: compiler.err.cant.ref.before.ctor.called: x
EarlyAssignments.java:139:22: compiler.err.cant.ref.before.ctor.called: x
EarlyAssignments.java:144:28: compiler.err.cant.ref.before.ctor.called: x
EarlyAssignments.java:153:13: compiler.err.cant.assign.initialized.before.ctor.called: x
EarlyAssignments.java:162:13: compiler.err.cant.assign.val.to.var: final, x
EarlyAssignments.java:173:13: compiler.err.cant.ref.before.ctor.called: this
EarlyAssignments.java:182:17: compiler.err.cant.ref.before.ctor.called: x
EarlyAssignments.java:37:34: compiler.err.cant.ref.before.ctor.called: x
EarlyAssignments.java:39:36: compiler.err.cant.ref.before.ctor.called: this
EarlyAssignments.java:43:17: compiler.err.cant.ref.before.ctor.called: x
EarlyAssignments.java:47:21: compiler.err.cant.ref.before.ctor.called: x
EarlyAssignments.java:51:22: compiler.err.cant.ref.before.ctor.called: x
EarlyAssignments.java:69:13: compiler.err.cant.ref.before.ctor.called: x
EarlyAssignments.java:70:17: compiler.err.cant.ref.before.ctor.called: x
EarlyAssignments.java:71:25: compiler.err.cant.ref.before.ctor.called: this
EarlyAssignments.java:72:31: compiler.err.cant.ref.before.ctor.called: this
EarlyAssignments.java:122:17: compiler.err.cant.ref.before.ctor.called: x
EarlyAssignments.java:127:22: compiler.err.cant.ref.before.ctor.called: x
EarlyAssignments.java:132:29: compiler.err.cant.ref.before.ctor.called: x
EarlyAssignments.java:137:22: compiler.err.cant.ref.before.ctor.called: x
EarlyAssignments.java:142:28: compiler.err.cant.ref.before.ctor.called: x
EarlyAssignments.java:151:13: compiler.err.cant.assign.initialized.before.ctor.called: x
EarlyAssignments.java:160:13: compiler.err.cant.assign.val.to.var: final, x
EarlyAssignments.java:171:13: compiler.err.cant.ref.before.ctor.called: this
EarlyAssignments.java:180:17: compiler.err.cant.ref.before.ctor.called: x
- compiler.note.preview.filename: EarlyAssignments.java, DEFAULT
- compiler.note.preview.recompile
21 errors
21 changes: 0 additions & 21 deletions test/langtools/tools/javac/SuperInit/EarlyAssignmentsWarnings.out

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
* jdk.compiler/com.sun.tools.javac.util
* @enablePreview
* @compile/fail/ref=EarlyInnerAccessErrorMessageTest.out -XDrawDiagnostics EarlyInnerAccessErrorMessageTest.java
* @build SuperCallRemover
* @compile/fail/ref=EarlyInnerAccessErrorMessageTestWarnings.out -Xlint:initialization -Werror -XDrawDiagnostics -processor SuperCallRemover EarlyInnerAccessErrorMessageTest.java
*/
public class EarlyInnerAccessErrorMessageTest {
int x;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
EarlyInnerAccessErrorMessageTest.java:17:34: compiler.err.cant.ref.before.ctor.called: x
EarlyInnerAccessErrorMessageTest.java:15:34: compiler.err.cant.ref.before.ctor.called: x
1 error

This file was deleted.

Loading