Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files
8259025: Record compact constructor using Objects.requireNonNull
Reviewed-by: attila
  • Loading branch information
lgxbslgx authored and szegedi committed Jan 11, 2021
1 parent 23801da commit 33fbc10cb8c869984159230b55ab9f3c9ca039ec
Showing with 13 additions and 3 deletions.
  1. +1 −1 src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java
  2. +12 −2 test/langtools/tools/javac/records/RecordCompilationTests.java
@@ -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;
}

@@ -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; }");

0 comments on commit 33fbc10

Please sign in to comment.