Skip to content
This repository was archived by the owner on Sep 2, 2022. It is now read-only.
/ jdk16 Public archive

8259025: Record compact constructor using Objects.requireNonNull #133

Closed
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
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1999, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1999, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -2962,7 +2962,6 @@ public void visitLambda(final JCLambda that) {
localEnv.info.isSerializable = true;
localEnv.info.isSerializableLambda = true;
}
localEnv.info.isLambda = true;
List<Type> explicitParamTypes = null;
if (that.paramKind == JCLambda.ParameterKind.EXPLICIT) {
//attribute lambda parameters
@@ -3404,6 +3403,7 @@ public Env<AttrContext> lambdaEnv(JCLambda that, Env<AttrContext> env) {
lambdaEnv = env.dup(that, env.info.dup(env.info.scope.dup()));
}
lambdaEnv.info.yieldResult = null;
lambdaEnv.info.isLambda = true;
return lambdaEnv;
}

14 changes: 12 additions & 2 deletions test/langtools/tools/javac/records/RecordCompilationTests.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2019, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -25,7 +25,7 @@
* RecordCompilationTests
*
* @test
* @bug 8250629 8252307 8247352 8241151 8246774
* @bug 8250629 8252307 8247352 8241151 8246774 8259025
* @summary Negative compilation tests, and positive compilation (smoke) tests for records
* @library /lib/combo /tools/lib /tools/javac/lib
* @modules
@@ -343,6 +343,16 @@ public void testConstructorRedeclaration() {

assertOK("import java.util.*; record R(String x, String y) { public R { Objects.requireNonNull(x); Objects.requireNonNull(y); } }");

// The lambda expressions in the constructor should be compiled successfully.
assertOK("""
import static java.util.Objects.*;
record R(String v) {
R {
requireNonNull(v, () -> "v must be provided");
requireNonNullElseGet(v, () -> "w");
}
}""");

// Not OK to redeclare canonical without DA
assertFail("compiler.err.var.might.not.have.been.initialized", "record R(int x, int y) { # }",
"public R(int x, int y) { this.x = x; }");