Path: blob/master/test/jdk/java/beans/XMLEncoder/Test6921644.java
41149 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* @run main/othervm -Djava.security.manager=allow Test692164428* @author Sergey Malenkov29*/3031import java.beans.ConstructorProperties;32import java.util.ArrayList;33import java.util.List;3435public final class Test6921644 extends AbstractTest {36public static void main(String[] args) {37new Test6921644().test(true);38}3940protected Object getObject() {41Owner<Author> o = new Owner<Author>(100); // it works if ID >= 1284243Category c = new Category(o);4445Document d1 = new Document(o);46Document d2 = new Document(o);47Document d3 = new Document(o);4849Author a1 = new Author(o);50Author a2 = new Author(o);51Author a3 = new Author(o);5253o.getList().add(a1);54o.getList().add(a2);55o.getList().add(a3);5657a3.setRef(o.getId());5859d2.setCategory(c);60d3.setCategory(c);6162a1.addDocument(d1);63a1.addDocument(d2);64a3.addDocument(d3);6566c.addDocument(d2);67c.addDocument(d3);6869return o;70}7172public static class Owner<T> {73private int id;74private List<T> list = new ArrayList<T>();7576@ConstructorProperties("id")77public Owner(int id) {78this.id = id;79}8081public int getId() {82return this.id;83}8485public List<T> getList() {86return this.list;87}8889public void setList(List<T> list) {90this.list = list;91}92}9394public static class Author {95private int id;96private int ref;97private Owner owner;98private List<Document> list = new ArrayList<Document>();99100@ConstructorProperties("owner")101public Author(Owner<Author> owner) {102this.owner = owner;103this.id = owner.getId();104}105106public Owner getOwner() {107return this.owner;108}109110public Integer getId() {111return this.id;112}113114public void setId(Integer id) {115this.id = id;116}117118public Integer getRef() {119return this.ref;120}121122public void setRef(Integer ref) {123this.ref = ref;124}125126public List<Document> getList() {127return this.list;128}129130public void setList(List<Document> list) {131this.list = list;132}133134public void addDocument(Document document) {135this.list.add(document);136document.setAuthor(this);137}138}139140public static class Category {141private Owner owner;142private List<Document> list = new ArrayList<Document>();143144@ConstructorProperties("owner")145public Category(Owner owner) {146this.owner = owner;147}148149public Owner getOwner() {150return this.owner;151}152153public List<Document> getList() {154return this.list;155}156157public void setList(List<Document> list) {158this.list = list;159}160161public void addDocument(Document document) {162this.list.add(document);163document.setCategory(this);164}165}166167public static class Document {168private Owner owner;169private Author author;170private Category category;171172@ConstructorProperties("owner")173public Document(Owner owner) {174this.owner = owner;175}176177public Owner getOwner() {178return this.owner;179}180181public Author getAuthor() {182return this.author;183}184185public void setAuthor(Author author) {186this.author = author;187}188189public Category getCategory() {190return this.category;191}192193public void setCategory(Category category) {194this.category = category;195}196}197}198199200