View Javadoc
1   /**
2    * Logback: the reliable, generic, fast and flexible logging framework.
3    * Copyright (C) 1999-2015, QOS.ch. All rights reserved.
4    *
5    * This program and the accompanying materials are dual-licensed under
6    * either the terms of the Eclipse Public License v1.0 as published by
7    * the Eclipse Foundation
8    *
9    *   or (per the licensee's choosing)
10   *
11   * under the terms of the GNU Lesser General Public License version 2.1
12   * as published by the Free Software Foundation.
13   */
14  package ch.qos.logback.classic.spi;
15  
16  import java.net.URL;
17  import java.net.URLClassLoader;
18  
19  /**
20   * A trivial class loader which throws a NoClassDefFoundError if the requested
21   * class name contains the string "Bogus".
22   * 
23   * @author Ceki Gulcu
24   */
25  public class BogusClassLoader extends URLClassLoader {
26  
27      public BogusClassLoader(URL[] urls) {
28          super(urls);
29      }
30  
31      public BogusClassLoader(URL[] urls, ClassLoader parent) {
32          super(urls, parent);
33      }
34  
35      public Class<?> loadClass(String name) throws ClassNotFoundException {
36          return loadClass(name, false);
37      }
38  
39      /**
40       * Throw NoClassDefFoundError if the requested class contains the string
41       * "Bogus". Otherwise, delegate to super-class.
42       */
43      protected Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException {
44  
45          if (name.contains("Bogus")) {
46              throw new NoClassDefFoundError();
47          }
48  
49          return super.loadClass(name, resolve);
50      }
51  }