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

Commit 408772c

Browse files
author
Vicente Romero
committed
8259025: Record compact constructor using Objects.requireNonNull
Reviewed-by: mcimadamore
1 parent 81e730e commit 408772c

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1999, 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1999, 2021, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -2962,7 +2962,6 @@ public void visitLambda(final JCLambda that) {
29622962
localEnv.info.isSerializable = true;
29632963
localEnv.info.isSerializableLambda = true;
29642964
}
2965-
localEnv.info.isLambda = true;
29662965
List<Type> explicitParamTypes = null;
29672966
if (that.paramKind == JCLambda.ParameterKind.EXPLICIT) {
29682967
//attribute lambda parameters
@@ -3404,6 +3403,7 @@ public Env<AttrContext> lambdaEnv(JCLambda that, Env<AttrContext> env) {
34043403
lambdaEnv = env.dup(that, env.info.dup(env.info.scope.dup()));
34053404
}
34063405
lambdaEnv.info.yieldResult = null;
3406+
lambdaEnv.info.isLambda = true;
34073407
return lambdaEnv;
34083408
}
34093409

test/langtools/tools/javac/records/RecordCompilationTests.java

+12-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2019, 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2019, 2021, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -25,7 +25,7 @@
2525
* RecordCompilationTests
2626
*
2727
* @test
28-
* @bug 8250629 8252307 8247352 8241151 8246774
28+
* @bug 8250629 8252307 8247352 8241151 8246774 8259025
2929
* @summary Negative compilation tests, and positive compilation (smoke) tests for records
3030
* @library /lib/combo /tools/lib /tools/javac/lib
3131
* @modules
@@ -343,6 +343,16 @@ public void testConstructorRedeclaration() {
343343

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

346+
// The lambda expressions in the constructor should be compiled successfully.
347+
assertOK("""
348+
import static java.util.Objects.*;
349+
record R(String v) {
350+
R {
351+
requireNonNull(v, () -> "v must be provided");
352+
requireNonNullElseGet(v, () -> "w");
353+
}
354+
}""");
355+
346356
// Not OK to redeclare canonical without DA
347357
assertFail("compiler.err.var.might.not.have.been.initialized", "record R(int x, int y) { # }",
348358
"public R(int x, int y) { this.x = x; }");

0 commit comments

Comments
 (0)