Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/beans/XMLEncoder/Test6921644.java
38812 views
/*1* Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @bug 692164426* @summary Tests references to cached integer27* @author Sergey Malenkov28*/2930import java.beans.ConstructorProperties;31import java.util.ArrayList;32import java.util.List;3334public final class Test6921644 extends AbstractTest {35public static void main(String[] args) {36new Test6921644().test(true);37}3839protected Object getObject() {40Owner<Author> o = new Owner<Author>(100); // it works if ID >= 1284142Category c = new Category(o);4344Document d1 = new Document(o);45Document d2 = new Document(o);46Document d3 = new Document(o);4748Author a1 = new Author(o);49Author a2 = new Author(o);50Author a3 = new Author(o);5152o.getList().add(a1);53o.getList().add(a2);54o.getList().add(a3);5556a3.setRef(o.getId());5758d2.setCategory(c);59d3.setCategory(c);6061a1.addDocument(d1);62a1.addDocument(d2);63a3.addDocument(d3);6465c.addDocument(d2);66c.addDocument(d3);6768return o;69}7071public static class Owner<T> {72private int id;73private List<T> list = new ArrayList<T>();7475@ConstructorProperties("id")76public Owner(int id) {77this.id = id;78}7980public int getId() {81return this.id;82}8384public List<T> getList() {85return this.list;86}8788public void setList(List<T> list) {89this.list = list;90}91}9293public static class Author {94private int id;95private int ref;96private Owner owner;97private List<Document> list = new ArrayList<Document>();9899@ConstructorProperties("owner")100public Author(Owner<Author> owner) {101this.owner = owner;102this.id = owner.getId();103}104105public Owner getOwner() {106return this.owner;107}108109public Integer getId() {110return this.id;111}112113public void setId(Integer id) {114this.id = id;115}116117public Integer getRef() {118return this.ref;119}120121public void setRef(Integer ref) {122this.ref = ref;123}124125public List<Document> getList() {126return this.list;127}128129public void setList(List<Document> list) {130this.list = list;131}132133public void addDocument(Document document) {134this.list.add(document);135document.setAuthor(this);136}137}138139public static class Category {140private Owner owner;141private List<Document> list = new ArrayList<Document>();142143@ConstructorProperties("owner")144public Category(Owner owner) {145this.owner = owner;146}147148public Owner getOwner() {149return this.owner;150}151152public List<Document> getList() {153return this.list;154}155156public void setList(List<Document> list) {157this.list = list;158}159160public void addDocument(Document document) {161this.list.add(document);162document.setCategory(this);163}164}165166public static class Document {167private Owner owner;168private Author author;169private Category category;170171@ConstructorProperties("owner")172public Document(Owner owner) {173this.owner = owner;174}175176public Owner getOwner() {177return this.owner;178}179180public Author getAuthor() {181return this.author;182}183184public void setAuthor(Author author) {185this.author = author;186}187188public Category getCategory() {189return this.category;190}191192public void setCategory(Category category) {193this.category = category;194}195}196}197198199