--- old/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Check.java 2020-07-29 11:38:37.078000000 -0700 +++ new/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Check.java 2020-07-29 11:38:36.410000000 -0700 @@ -29,6 +29,7 @@ import java.util.function.Supplier; import javax.lang.model.element.ElementKind; +import javax.lang.model.element.NestingKind; import javax.tools.JavaFileManager; import com.sun.tools.javac.code.*; @@ -2366,7 +2367,7 @@ tv.setUpperBound(types.createErrorType(t)); log.error(pos, Errors.CyclicInheritance(t)); } else if (t.hasTag(TYPEVAR)) { - tv = (TypeVar)t; + tv = (TypeVar)t; seen = seen.prepend(tv); for (Type b : types.getBounds(tv)) checkNonCyclic1(pos, b, seen); @@ -3827,6 +3828,53 @@ } } + /** + * Check for a default constructor in an exported package. + */ + void checkDefaultConstructor(ClassSymbol c, DiagnosticPosition pos) { + if (lint.isEnabled(Lint.LintCategory.DEFAULT_CTOR) && + (c.flags() & ENUM) == 0 && + !c.isAnonymous() && + ((c.flags() & PUBLIC) != 0) && + Feature.MODULES.allowedInSource(source)) { + NestingKind nestingKind = c.getNestingKind(); + switch (nestingKind) { + case ANONYMOUS, + LOCAL -> {return;} + case TOP_LEVEL -> {;} // No additional checks needed + case MEMBER -> { + // For nested member classes, all the enclosing + // classes must be public. + Symbol owner = c.owner; + while (owner != null && owner.kind == TYP) { + if ((owner.flags() & PUBLIC) == 0) + return; + owner = owner.owner; + } + } + } + + // Only check classes in named packages exported by its module + PackageSymbol pkg = c.packge(); + if (!pkg.isUnnamed()) { + ModuleSymbol modle = pkg.modle; + for (ExportsDirective exportDir : modle.exports) { + // Report warning only if the containing + // package is unconditionally exported + if (exportDir.packge.equals(pkg)) { + if (exportDir.modules == null || exportDir.modules.isEmpty()) { + log.warning(LintCategory.DEFAULT_CTOR, + pos, Warnings.DefaultCtor(c, pkg, modle)); + } else { + return; + } + } + } + } + } + return; + } + private class ConversionWarner extends Warner { final String uncheckedKey; final Type found;