001/** 002 * Logback: the reliable, generic, fast and flexible logging framework. 003 * Copyright (C) 1999-2015, QOS.ch. All rights reserved. 004 * 005 * This program and the accompanying materials are dual-licensed under 006 * either the terms of the Eclipse Public License v1.0 as published by 007 * the Eclipse Foundation 008 * 009 * or (per the licensee's choosing) 010 * 011 * under the terms of the GNU Lesser General Public License version 2.1 012 * as published by the Free Software Foundation. 013 */ 014package ch.qos.logback.classic.spi; 015 016import java.net.URL; 017import java.net.URLClassLoader; 018 019/** 020 * A trivial class loader which throws a NoClassDefFoundError if the requested 021 * class name contains the string "Bogus". 022 * 023 * @author Ceki Gulcu 024 */ 025public class BogusClassLoader extends URLClassLoader { 026 027 public BogusClassLoader(URL[] urls) { 028 super(urls); 029 } 030 031 public BogusClassLoader(URL[] urls, ClassLoader parent) { 032 super(urls, parent); 033 } 034 035 public Class<?> loadClass(String name) throws ClassNotFoundException { 036 return loadClass(name, false); 037 } 038 039 /** 040 * Throw NoClassDefFoundError if the requested class contains the string 041 * "Bogus". Otherwise, delegate to super-class. 042 */ 043 protected Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException { 044 045 if (name.contains("Bogus")) { 046 throw new NoClassDefFoundError(); 047 } 048 049 return super.loadClass(name, resolve); 050 } 051}