<commit_before>/*
 * Copyright (c) 2006-2011 <NAME>
 * This file is subject to the terms of the MIT license (see LICENSE.txt).
 */
package mockit.multicore;

import java.io.*;
import java.net.*;
import java.util.*;

import mockit.internal.*;

final class CopyingClassLoader extends ClassLoader
{
   private static final ClassLoader SYSTEM_CL = ClassLoader.getSystemClassLoader();

   CopyingClassLoader()
   {
      super(SYSTEM_CL.getParent());
   }

   Class<?> getCopy(String className)
   {
      return findClass(className);
   }

   @Override
   protected synchronized Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException
   {
      if (
         name.startsWith("org.junit.") || name.startsWith("junit.framework.") ||
         name.startsWith("mockit.") && !name.startsWith("mockit.integration.logging.")
      ) {
         assert !resolve;
         return SYSTEM_CL.loadClass(name);
      }

      return super.loadClass(name, resolve);
   }

   @Override
   protected Class<?> findClass(String name)
   {
      Class<?> loadedClass = findLoadedClass(name);

      if (loadedClass != null) {
         return loadedClass;
      }

      definePackageForCopiedClass(name);
      
      byte[] classBytecode = ClassFile.createClassFileReader(name).b;
      return defineClass(name, classBytecode, 0, classBytecode.length);
   }

   private void definePackageForCopiedClass(String name)
   {
      int p = name.lastIndexOf('.');

      if (p > 0) {
         String packageName = name.substring(0, p);

         if (getPackage(packageName) == null) {
            definePackage(packageName, null, null, null, null, null, null, null);
         }
      }
   }

   boolean hasLoadedClass(Class<?> aClass)
   {
      return findLoadedClass(aClass.getName()) != null;
   }

   @Override
   protected URL findResource(String name)
   {
      return SYSTEM_CL.getResource(name);
   }

   @Override
   protected Enumeration<URL> findResources(String name) throws IOException
   {
      return SYSTEM_CL.getResources(name);
   }
}<commit_msg>Two minor improvements.<commit_after>/*
 * Copyright (c) 2006-2011 <NAME>
 * This file is subject to the terms of the MIT license (see LICENSE.txt).
 */
package mockit.multicore;

import java.io.*;
import java.net.*;
import java.util.*;

import mockit.internal.*;

final class CopyingClassLoader extends ClassLoader
{
   private static final ClassLoader SYSTEM_CL = ClassLoader.getSystemClassLoader();

   CopyingClassLoader()
   {
      super(SYSTEM_CL.getParent());
   }

   Class<?> getCopy(String className)
   {
      return findClass(className);
   }

   @Override
   protected synchronized Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException
   {
      if (
         name.startsWith("org.junit.") || name.startsWith("junit.framework.") ||
         name.startsWith("mockit.") && !name.startsWith("mockit.integration.logging.")
      ) {
         Class<?> theClass = SYSTEM_CL.loadClass(name);

         if (resolve) {
            resolveClass(theClass);
         }

         return theClass;
      }

      return super.loadClass(name, resolve);
   }

   @Override
   protected Class<?> findClass(String name)
   {
      Class<?> loadedClass = findLoadedClass(name);

      if (loadedClass != null) {
         return loadedClass;
      }

      definePackageForCopiedClass(name);
      
      byte[] classBytecode = ClassFile.createClassFileReader(name).b;
      return defineClass(name, classBytecode, 0, classBytecode.length);
   }

   private void definePackageForCopiedClass(String name)
   {
      int p = name.lastIndexOf('.');

      if (p > 0) {
         String packageName = name.substring(0, p);

         if (getPackage(packageName) == null) {
            definePackage(packageName, null, null, null, null, null, null, null);
         }
      }
   }

   boolean hasLoadedClass(Class<?> aClass)
   {
      return findLoadedClass(aClass.getName()) != null;
   }

   @Override
   protected URL findResource(String name)
   {
      URL resource;

      // Somehow, getResource returns null sometimes, but retrying eventually works.
      do {
         resource = SYSTEM_CL.getResource(name);
      }
      while (resource == null);

      return resource;
   }

   @Override
   protected Enumeration<URL> findResources(String name) throws IOException
   {
      return SYSTEM_CL.getResources(name);
   }
}
{'fraction_non_alphanumeric': 0.11393554244212438, 'fraction_numerical': 0.004993191103041307, 'mean_word_length': 2.8155844155844156, 'pattern_counts': {'":': 0, '<': 18, '<?xml version=': 0, '>': 20, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6267646', 'n_tokens_mistral': 1293, 'n_tokens_neox': 1251, 'n_words': 297}