Skip to content
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1459,7 +1459,7 @@ jobs:
timeout-minutes: 60
strategy:
matrix:
java: [ '17', '25' ]
java: [ '17', '25', '26-ea' ]
config: [ 'batch1', 'batch2' ]
Comment on lines 1461 to 1463
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note to self: probably better to reduce the matrix to upper/lower bound, otherwise this job would cause too many manual restarts when both batches run three times.

exclude:
- java: ${{ github.event_name == 'pull_request' && 'nothing' || '25' }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -763,7 +763,7 @@ private void insideClass(Env env) throws IOException {
String headerText = controller.getText().substring(startPos, offset);
int idx = headerText.indexOf('{'); //NOI18N
//see JDK-8364015, unclear how reliable this will be:
boolean isImplicitlyDeclaredClass = sourcePositions.getEndPosition(root, cls) == (-1);
boolean isImplicitlyDeclaredClass = env.getController().getTreeUtilities().isImplicitlyDeclaredClass(cls);
if (idx >= 0 || isImplicitlyDeclaredClass) {
addKeywordsForClassBody(env);
addClassTypes(env, null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1919,7 +1919,7 @@ private static TypeMirror attributeTree(JavacTaskImpl jti, Tree tree, Scope scop
Log.DiagnosticHandler discardHandler = log.new DiscardDiagnosticHandler() {
private Diagnostic.Kind f = filter == null ? Diagnostic.Kind.ERROR : filter;
@Override
public void report(JCDiagnostic diag) {
public void reportReady(JCDiagnostic diag) {
if (diag.getKind().compareTo(f) >= 0) {
errors.add(diag);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3:4-3:13:error:method does not override or implement a method from a supertype
3:4-3:13:error:t() in TestOverrideAnnotation does not override or implement a method from a supertype
Original file line number Diff line number Diff line change
Expand Up @@ -249,9 +249,7 @@ void main() {
}
""",
"21",
//TODO: can this comment be now removed?
//TODO: needs to be adjusted when the error in javac is fixed:
"0:0-0:13::Test.java:1:1: compiler.err.feature.not.supported.in.source.plural: (compiler.misc.feature.implicit.classes), 21, " + SourceVersion.latest().ordinal());
"0:0-0:13::Test.java:1:1: compiler.err.feature.not.supported.in.source.plural: (compiler.misc.feature.implicit.classes), 21, 25");
}

private void performInlinedTest(String name, String code) throws Exception {
Expand Down
2 changes: 1 addition & 1 deletion java/java.source.base/nbproject/project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ javadoc.name=Java Source Base
javadoc.title=Java Source Base
javadoc.arch=${basedir}/arch.xml
javadoc.apichanges=${basedir}/apichanges.xml
spec.version.base=2.81.0
spec.version.base=2.82.0
test.qa-functional.cp.extra=${refactoring.java.dir}/modules/ext/nb-javac-api.jar
test.unit.run.cp.extra=${o.n.core.dir}/core/core.jar:\
${o.n.core.dir}/lib/boot.jar:\
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
import com.sun.tools.javac.model.JavacElements;
import com.sun.tools.javac.tree.JCTree.JCCompilationUnit;
import com.sun.tools.javac.util.Context;
import com.sun.tools.javac.util.Log;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
Expand Down Expand Up @@ -176,16 +177,23 @@ public static Set<TreePath> computeDuplicates(CompilationInfo info, TreePath sea

public static boolean checkTypesAssignable(CompilationInfo info, TypeMirror from, TypeMirror to) {
Context c = ((JavacTaskImpl) info.impl.getJavacTask()).getContext();
if (from.getKind() == TypeKind.TYPEVAR) {
Types types = Types.instance(c);
TypeVar t = types.substBound((TypeVar)from, com.sun.tools.javac.util.List.of((Type)from), com.sun.tools.javac.util.List.of(types.boxedTypeOrType((Type)to)));
return info.getTypes().isAssignable(t.getUpperBound(), to)
|| info.getTypes().isAssignable(to, t.getUpperBound());
}
if (from.getKind() == TypeKind.WILDCARD) {
from = Types.instance(c).wildUpperBound((Type)from);
Log log = Log.instance(c);
//TODO: need to throw away all warnings, as a) reporting the warnings is wrong anyway; b) the default handler may crash; are there more places that require similar handling?
Log.DiagnosticHandler discardHandler = log.new DiscardDiagnosticHandler();
try {
if (from.getKind() == TypeKind.TYPEVAR) {
Types types = Types.instance(c);
TypeVar t = types.substBound((TypeVar)from, com.sun.tools.javac.util.List.of((Type)from), com.sun.tools.javac.util.List.of(types.boxedTypeOrType((Type)to)));
return info.getTypes().isAssignable(t.getUpperBound(), to)
|| info.getTypes().isAssignable(to, t.getUpperBound());
}
if (from.getKind() == TypeKind.WILDCARD) {
from = Types.instance(c).wildUpperBound((Type)from);
}
return Check.instance(c).checkType(null, (Type)from, (Type)to).getKind() != TypeKind.ERROR;
} finally {
log.popDiagnosticHandler(discardHandler);
}
return Check.instance(c).checkType(null, (Type)from, (Type)to).getKind() != TypeKind.ERROR;
}

public static TypeMirror getBound(WildcardType wildcardType) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -446,11 +446,6 @@ public Void scan(Tree tree, Void p) {
endPos = sourcePositions.getEndPosition(cut, value);
}
break;
case CLASS:
if (tree instanceof JCClassDecl clazz && (clazz.mods.flags & Flags.IMPLICIT_CLASS) != 0) {
endPos = sourcePositions.getEndPosition(cut, cut);
}
break;
}
}
if (startPos < pos && endPos >= pos) {
Expand Down Expand Up @@ -512,8 +507,16 @@ public Void visitEnhancedForLoop(EnhancedForLoopTree node, Void p) {
path = result.path;
}

if (path.getLeaf() == path.getCompilationUnit())
if (path.getLeaf() == path.getCompilationUnit()) {
long endPos = sourcePositions.getEndPosition(path.getCompilationUnit(), path.getCompilationUnit());
if (pos > endPos) {
List<? extends Tree> classes = path.getCompilationUnit().getTypeDecls();
if (classes.size() == 1 && classes.get(0) instanceof JCClassDecl clazz && (clazz.mods.flags & Flags.IMPLICIT_CLASS) != 0) {
return new TreePath(path, clazz);
}
}
return path;
}

TokenSequence<JavaTokenId> tokenList = tokensFor(path.getLeaf(), sourcePositions, pos);
tokenList.moveEnd();
Expand Down Expand Up @@ -970,7 +973,7 @@ private static TypeMirror attributeTree(JavacTaskImpl jti, CompilationUnitTree c
JavaFileObject prev = log.useSource(new DummyJFO());
Log.DiagnosticHandler discardHandler = log.new DiscardDiagnosticHandler() {
@Override
public void report(JCDiagnostic diag) {
public void reportReady(JCDiagnostic diag) {
errors.add(diag);
}
};
Expand Down Expand Up @@ -1010,7 +1013,7 @@ private static Scope attributeTreeTo(JavacTaskImpl jti, CompilationUnitTree cut,
JavaFileObject prev = log.useSource(new DummyJFO());
Log.DiagnosticHandler discardHandler = log.new DiscardDiagnosticHandler() {
@Override
public void report(JCDiagnostic diag) {
public void reportReady(JCDiagnostic diag) {
errors.add(diag);
}
};
Expand Down Expand Up @@ -2125,6 +2128,15 @@ public boolean hasError(@NonNull Tree tree, String... errors) {
return false;
}

/**
* {@return {@code true} iff the given class is the implicit class in the compact source file.}
* @param tree class to check
* @since 2.82
*/
public boolean isImplicitlyDeclaredClass(@NonNull ClassTree tree) {
return tree instanceof JCClassDecl clazz && (clazz.mods.flags & Flags.IMPLICIT_CLASS) != 0;
}

private static final class NBScope implements Scope {

private final JavacScope delegate;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
*/
public class NoJavacHelper {

public static final int REQUIRED_JAVAC_VERSION = 25; // <- TODO: increment on every release
public static final int REQUIRED_JAVAC_VERSION = 26; // <- TODO: increment on every release
private static final boolean HAS_WORKING_JAVAC;

static {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@

import com.sun.tools.javac.code.Symtab;
import com.sun.tools.javac.util.JCDiagnostic.Error;
import java.util.Set;
import org.netbeans.modules.java.source.builder.ElementsService;

/**
Expand Down Expand Up @@ -151,7 +152,7 @@ public void visitMethodDef(JCMethodDecl tree) {
&& !type.isErroneous()
&& types.isSameType(types.erasure(sym.type), type);
if (clash) {
log.error(tree.pos(), new Error("compiler", "name.clash.same.erasure", tree.sym, sym)); //NOI18N
log.error(tree.pos(), new Error(Set.of(), "compiler", "name.clash.same.erasure", tree.sym, sym)); //NOI18N
return;
}
} catch (AssertionError e) {}
Expand Down Expand Up @@ -201,7 +202,7 @@ private void checkThis(DiagnosticPosition pos, TypeSymbol c) {
if (checkThis && currentClass != c) {
List<Pair<TypeSymbol, Symbol>> ots = outerThisStack;
if (ots.isEmpty()) {
log.error(pos, new Error("compiler", "no.encl.instance.of.type.in.scope", c)); //NOI18N
log.error(pos, new Error(Set.of(), "compiler", "no.encl.instance.of.type.in.scope", c)); //NOI18N
return;
}
Pair<TypeSymbol, Symbol> ot = ots.head;
Expand All @@ -210,13 +211,13 @@ private void checkThis(DiagnosticPosition pos, TypeSymbol c) {
do {
ots = ots.tail;
if (ots.isEmpty()) {
log.error(pos, new Error("compiler", "no.encl.instance.of.type.in.scope", c)); //NOI18N
log.error(pos, new Error(Set.of(), "compiler", "no.encl.instance.of.type.in.scope", c)); //NOI18N
return;
}
ot = ots.head;
} while (ot.snd != otc);
if (otc.owner.kind != Kinds.Kind.PCK && !otc.hasOuterInstance()) {
log.error(pos, new Error("compiler", "cant.ref.before.ctor.called", c)); //NOI18N
log.error(pos, new Error(Set.of(), "compiler", "cant.ref.before.ctor.called", c)); //NOI18N
return;
}
otc = ot.fst;
Expand All @@ -233,7 +234,7 @@ private void outerThisDef(Symbol owner) {
private static final int MAX_STRING_LENGTH = 65535;
private void checkStringConstant(DiagnosticPosition pos, Object constValue) {
if (constValue instanceof String && ((String)constValue).length() >= MAX_STRING_LENGTH)
log.error(pos, new Error("compiler", "limit.string")); //NOI18N
log.error(pos, new Error(Set.of(), "compiler", "limit.string")); //NOI18N
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -348,23 +348,11 @@ private com.sun.tools.javac.parser.JavacParser newParser(Context context, CharSe
}
return new NBParserFactory.NBJavacParser(parserFactory, lexer, true, false, true, false, cancelService) {
@Override protected com.sun.tools.javac.parser.JavacParser.AbstractEndPosTable newEndPosTable(boolean keepEndPositions) {
return new com.sun.tools.javac.parser.JavacParser.AbstractEndPosTable(this) {
return new com.sun.tools.javac.parser.JavacParser.AbstractEndPosTable() {

@Override
public void storeEnd(JCTree tree, int endpos) {
((NBParserFactory.NBJavacParser.EndPosTableImpl)endPos).storeEnd(tree, endpos);
}

@Override
protected <T extends JCTree> T to(T t) {
storeEnd(t, token.endPos);
return t;
}

@Override
protected <T extends JCTree> T toP(T t) {
storeEnd(t, S.prevToken().endPos);
return t;
public <T extends JCTree> T storeEnd(T tree, int endpos) {
return ((NBParserFactory.NBJavacParser.EndPosTableImpl)endPos).storeEnd(tree, endpos);
}

@Override
Expand Down Expand Up @@ -410,7 +398,7 @@ public BlockTree reattrMethodBody(Context context, Scope scope, MethodTree metho
// in enum constructors, except in the compiler
// generated one.
log.error(tree.body.stats.head.pos(),
new JCDiagnostic.Error("compiler",
new JCDiagnostic.Error(Set.of(), "compiler",
"call.to.super.not.allowed.in.enum.ctor",
env.enclClass.sym));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2902,13 +2902,14 @@ else if (addSpace)
}
}

private static final String[] flagLowerCaseNames = new String[Flag.values().length];
private static final String[] flagLowerCaseNames = new String[FlagsEnum.values().length];

static {
for (Flag flag : Flag.values()) {
for (FlagsEnum flag : FlagsEnum.values()) {
flagLowerCaseNames[flag.ordinal()] = flag.name().toLowerCase(Locale.ENGLISH);
}
flagLowerCaseNames[Flag.NON_SEALED.ordinal()] = "non-sealed";
flagLowerCaseNames[FlagsEnum.NON_SEALED.ordinal()] = "non-sealed";
flagLowerCaseNames[FlagsEnum.TRANSIENT_OR_ACC_VARARGS.ordinal()] = "transient"; //TODO: there should be a test in java.source.base for this
}

/**
Expand All @@ -2922,7 +2923,7 @@ public static String flagNames(long flags) {
flags = flags & Flags.ExtendedStandardFlags;
StringBuilder buf = new StringBuilder();
String sep = ""; // NOI18N
for (Flag flag : Flags.asFlagSet(flags)) {
for (FlagsEnum flag : Flags.asFlagSet(flags)) {
buf.append(sep);
String fname = flagLowerCaseNames[flag.ordinal()];
buf.append(fname);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2502,13 +2502,12 @@ record Data(ErrorKind kind, Pair<Pair<Integer, Integer>, Pair<Integer, Integer>>
public Data get(ErrorKind kind, Range range, String message) {
return new Data(kind, Pair.of(Pair.of(range.start().line(),
range.start().column()),
range.end() != null ? Pair.of(range.end().line(),
range.end().column())
: null));
Pair.of(range.end().line(),
range.end().column())));
}
});
assertEquals(List.of(new Data(ErrorKind.WARNING, Pair.of(Pair.of(4, 9), Pair.of(4, 19))),
new Data(ErrorKind.WARNING, Pair.of(Pair.of(4, 17), null))),
new Data(ErrorKind.WARNING, Pair.of(Pair.of(4, 17), Pair.of(4, 17)))),
errors);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import com.sun.tools.javac.util.Names;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.util.Set;
import java.util.function.Supplier;
import java.util.logging.Level;
import java.util.logging.Logger;
Expand Down Expand Up @@ -107,7 +108,7 @@ public Completer getCompleter() {
Constructor<CompletionFailure> constr = CompletionFailure.class.getDeclaredConstructor(Symbol.class, Supplier.class, dcfhClass);
Object dcfh = dcfhClass.getDeclaredMethod("instance", Context.class).invoke(null, context);
throw constr.newInstance(sym, (Supplier<JCDiagnostic>) () -> {
return diagFactory.create(log.currentSource(), new SimpleDiagnosticPosition(0), DiagnosticInfo.of(DiagnosticType.ERROR, "compiler", "cant.resolve", "package", "java.lang"));
return diagFactory.create(log.currentSource(), new SimpleDiagnosticPosition(0), DiagnosticInfo.of(DiagnosticType.ERROR, Set.of(), "compiler", "cant.resolve", "package", "java.lang"));
}, dcfh);
} catch (ClassNotFoundException | NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | InstantiationException ex) {
Logger.getLogger(NBClassFinder.class.getName()).log(Level.FINE, null, ex);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public JCCompilationUnit parseCompilationUnit() {

if (!unit.getTypeDecls().isEmpty() && unit.getTypeDecls().get(0).getKind() == Kind.CLASS) {
JCClassDecl firstClass = (JCClassDecl) unit.getTypeDecls().get(0);
if ((firstClass.mods.flags & Flags.IMPLICIT_CLASS) != 0 && getEndPos(unit) == Position.NOPOS) {
if ((firstClass.mods.flags & Flags.IMPLICIT_CLASS) != 0) {
if (pack[0] != null) {
unit.defs = unit.defs.prepend(pack[0]);
}
Expand All @@ -115,7 +115,6 @@ public JCCompilationUnit parseCompilationUnit() {
}

firstClass.pos = newPos;
endPosTable.storeEnd(unit, token.endPos);
}
}
return unit;
Expand Down Expand Up @@ -188,12 +187,9 @@ public JCStatement parseSimpleStatement() {

public final class EndPosTableImpl extends AbstractEndPosTable {

private final Lexer lexer;
private final SimpleEndPosTable delegate;

private EndPosTableImpl(Lexer lexer, JavacParser parser, SimpleEndPosTable delegate) {
super(parser);
this.lexer = lexer;
this.delegate = delegate;
}

Expand All @@ -202,9 +198,11 @@ public void resetErrorEndPos() {
errorEndPos = delegate.errorEndPos;
}

@Override public void storeEnd(JCTree tree, int endpos) {
@Override
public <T extends JCTree> T storeEnd(T tree, int endpos) {
if (endpos >= 0)
delegate.storeEnd(tree, endpos);
return delegate.storeEnd(tree, endpos);
return null;
}

public void setEnd(JCTree tree, int endpos) {
Expand All @@ -225,18 +223,6 @@ public void setErrorEndPos(int errPos) {
errorEndPos = delegate.errorEndPos;
}

@Override
protected <T extends JCTree> T to(T t) {
storeEnd(t, parser.token().endPos);
return t;
}

@Override
protected <T extends JCTree> T toP(T t) {
storeEnd(t, lexer.prevToken().endPos);
return t;
}

@Override
public int getEndPos(JCTree jctree) {
return delegate.getEndPos(jctree);
Expand Down
Loading
Loading