title: Java classloaders: why search the parent classloader first?
body: <p>The correct behaviour for a classloader in Java is to:</p>
  
  <ol>
  <li>If it has already been loaded, return the class</li>
  <li>Call the parent loadClass()</li>
  <li>Try and load the class itself.</li>
  </ol>
  
  <p>So the class defined in the system classpath should always get loaded first. Tomcat defines classloader per war, which has the system classloader as a parent, so if you try to load a class, it will first look in the system classpath and then in the classpath defined in the war file.</p>
  
  <p>As per my understanding, this is for two reasons:</p>
  
  <ol>
  <li>To avoid problems with different versions of classes being used. Imagine I redefined java.lang.Object in a war, it would be a nightmare.</li>
  <li>To avoid dependencies on child classloaders: The system classloader cannot depend on child classloaders: it would be hard to redeploy a war, for instance.</li>
  </ol>
  
  <p>So, the question is:</p>
  
  <p>In addition to the above problems, are there any other pitfalls to implementing a classloader which does not do a parent search first?</p>