diff options
author | Manoj Palat | 2020-08-14 05:04:34 +0000 |
---|---|---|
committer | Manoj Palat | 2020-08-14 05:04:34 +0000 |
commit | e5e0eecd92d4e497573f4df8043c4ac92e394ad1 (patch) | |
tree | 98bb5d2c2ec7b8809328f1cd2bf9056b03efafdf | |
parent | 14a1543a5017774ddbcf68bf8adae8e99ee91cec (diff) | |
download | eclipse.jdt.core-e5e0eecd92d4e497573f4df8043c4ac92e394ad1.tar.gz eclipse.jdt.core-e5e0eecd92d4e497573f4df8043c4ac92e394ad1.tar.xz eclipse.jdt.core-e5e0eecd92d4e497573f4df8043c4ac92e394ad1.zip |
Bug 565830 - record - nested record contains reference to the enclosingI20200815-0600I20200814-1800I20200814-1040I20200814-0640I20200814-0330
instance
Change-Id: I44d8f11f1ef5e55eaaf8c2675a530ab2fd709fba
Signed-off-by: Manoj Palat <manpalat@in.ibm.com>
2 files changed, 29 insertions, 0 deletions
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/RecordsRestrictedClassTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/RecordsRestrictedClassTest.java index 314a5532b0..6de0a9b851 100644 --- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/RecordsRestrictedClassTest.java +++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/RecordsRestrictedClassTest.java @@ -3898,4 +3898,28 @@ public void testBug564146_007() { }, "10"); } +public void testBug565830_01() { + runConformTest( + new String[] { + "X.java", + "class X {\n"+ + " void bar() throws Exception {\n"+ + " record Bar(int x) implements java.io.Serializable {\n"+ + " void printMyFields() {\n"+ + " for (var field : this.getClass().getDeclaredFields()) {\n"+ + " System.out.println(field);\n"+ + " }\n"+ + " }\n"+ + " }\n"+ + " var bar = new Bar(1);\n"+ + " bar.printMyFields();\n"+ + " new java.io.ObjectOutputStream(java.io.OutputStream.nullOutputStream()).writeObject(bar);\n"+ + " }\n"+ + " public static void main(String[] args) throws Exception {\n"+ + " new X().bar();\n"+ + " }\n"+ + "}", + }, + "private final int X$1Bar.x"); +} }
\ No newline at end of file diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/NestedTypeBinding.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/NestedTypeBinding.java index 529574f0d0..90f7a9beef 100644 --- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/NestedTypeBinding.java +++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/NestedTypeBinding.java @@ -77,9 +77,14 @@ public SyntheticArgumentBinding addSyntheticArgument(LocalVariableBinding actual /* Add a new synthetic argument for <enclosingType>. * Answer the new argument or the existing argument if one already existed. +* Do not add if this is static (eg. nested records) */ public SyntheticArgumentBinding addSyntheticArgument(ReferenceBinding targetEnclosingType) { if (!isPrototype()) throw new IllegalStateException(); + if (isStatic()) { + assert this.isRecord();// a local record is implicitly static; no other local type can be static + return null; + } SyntheticArgumentBinding synthLocal = null; if (this.enclosingInstances == null) { synthLocal = new SyntheticArgumentBinding(targetEnclosingType); |