Path: blob/master/test/jdk/java/beans/Beans/TypoInBeanDescription.java
41149 views
/*1* Copyright (c) 2018, 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*/2223import java.beans.BeanInfo;24import java.beans.IntrospectionException;25import java.beans.Introspector;26import java.io.IOException;27import java.net.URI;28import java.nio.file.FileSystem;29import java.nio.file.FileSystems;30import java.nio.file.FileVisitResult;31import java.nio.file.Files;32import java.nio.file.Path;33import java.nio.file.SimpleFileVisitor;34import java.nio.file.attribute.BasicFileAttributes;3536/**37* @test38* @bug 820545439*/40public final class TypoInBeanDescription {4142private static final String[] typos = {"&", "<", ">", """};4344public static void main(final String[] args) throws IOException {45FileSystem fs = FileSystems.getFileSystem(URI.create("jrt:/"));46Files.walkFileTree(fs.getPath("/modules/java.desktop"), new SimpleFileVisitor<>() {47@Override48public FileVisitResult visitFile(Path file,49BasicFileAttributes attrs) {50file = file.subpath(2, file.getNameCount());51String name = file.toString();52if (name.endsWith(".class")) {53name = name.substring(0, name.indexOf(".")).replace('/', '.');5455final Class<?> type;56try {57type = Class.forName(name);58} catch (Throwable e) {59return FileVisitResult.CONTINUE;60}61final BeanInfo beanInfo;62try {63beanInfo = Introspector.getBeanInfo(type);64} catch (IntrospectionException e) {65return FileVisitResult.CONTINUE;66}67test(beanInfo);68}69return FileVisitResult.CONTINUE;70}71});72}7374private static void test(final BeanInfo beanInfo) {75for (var pd : beanInfo.getPropertyDescriptors()) {76String d = pd.getShortDescription();77String n = pd.getName();78String dn = pd.getDisplayName();79for (String typo : typos) {80if (d.contains(typo) || n.contains(typo) || dn.contains(typo)) {81throw new RuntimeException("Wrong name: " + beanInfo.getBeanDescriptor());82}83}84}85}86}878889