<commit_before>package org.jboss.forge.furnace.util;

import java.util.concurrent.Callable;
import java.util.logging.Level;
import java.util.logging.Logger;

import org.jboss.forge.furnace.exception.ContainerException;

/**
 * Utility class for executing fragments of code within a specific {@link Thread#getContextClassLoader()}
 * 
 * @author <a href="mailto:<EMAIL>"><NAME>, III</a>
 */
public class ClassLoaders
{
   private static Logger log = Logger.getLogger(ClassLoaders.class.getName());

   /**
    * Execute the given {@link Callable} in the {@link ClassLoader} provided. Return the result, if any.
    */
   public static <T> T executeIn(ClassLoader loader, Callable<T> task) throws Exception
   {
      if (task == null)
         return null;

      if (log.isLoggable(Level.FINE))
      {
         log.fine("ClassLoader [" + loader + "] task began.");
      }
      ClassLoader original = SecurityActions.getContextClassLoader();
      try
      {
         SecurityActions.setContextClassLoader(loader);
         return task.call();
      }
      finally
      {
         SecurityActions.setContextClassLoader(original);
         if (log.isLoggable(Level.FINE))
         {
            log.fine("ClassLoader [" + loader + "] task ended.");
         }
      }
   }

   public static boolean containsClass(ClassLoader loader, Class<?> type)
   {
      if (loader == null)
         throw new IllegalArgumentException("Class loader to inspect must not be null.");
      if (type == null)
         throw new IllegalArgumentException("Class to find must not be null.");

      try
      {
         return loader.loadClass(type.getName()) == type;
      }
      catch (ClassNotFoundException | LinkageError e)
      {
         return false;
      }
   }

   public static boolean containsClass(ClassLoader loader, String type)
   {
      if (loader == null)
         throw new IllegalArgumentException("Class loader to inspect must not be null.");
      if (type == null)
         throw new IllegalArgumentException("Class to find must not be null.");

      try
      {
         loader.loadClass(type);
         return true;
      }
      catch (ClassNotFoundException | LinkageError e)
      {
         return false;
      }
   }

   public static Class<?> loadClass(ClassLoader loader, String typeName)
   {
      if (loader == null)
         throw new IllegalArgumentException("Class loader to inspect must not be null.");
      if (typeName == null)
         throw new IllegalArgumentException("Class name to find must not be null.");

      try
      {
         return loader.loadClass(typeName);
      }
      catch (ClassNotFoundException | LinkageError e)
      {
         throw new ContainerException("Could not locate class [" + typeName + "] in Loader [" + loader + "]", e);
      }
   }

   public static Class<?> loadClass(ClassLoader loader, Class<?> type)
   {
      if (loader == null)
         throw new IllegalArgumentException("Class loader to inspect must not be null.");
      if (type == null)
         throw new IllegalArgumentException("Class to find must not be null.");

      try
      {
         return loader.loadClass(type.getName());
      }
      catch (ClassNotFoundException | LinkageError e)
      {
         throw new ContainerException("Could not locate class [" + type.getName() + "] in Loader [" + loader + "]", e);
      }
   }

   public static boolean ownsClass(ClassLoader loader, Class<?> type)
   {
      if (loader == null)
         throw new IllegalArgumentException("Class loader to inspect must not be null.");
      if (type == null)
         throw new IllegalArgumentException("Class to find must not be null.");

      return type.getClassLoader().equals(loader);
   }<commit_msg>Fixed possible NullPointerException when type.getClassLoader() is null<commit_after>package org.jboss.forge.furnace.util;

import java.util.concurrent.Callable;
import java.util.logging.Level;
import java.util.logging.Logger;

import org.jboss.forge.furnace.exception.ContainerException;

/**
 * Utility class for executing fragments of code within a specific {@link Thread#getContextClassLoader()}
 *
 * @author <a href="mailto:<EMAIL>"><NAME>, III</a>
 */
public class ClassLoaders
{
   private static Logger log = Logger.getLogger(ClassLoaders.class.getName());

   /**
    * Execute the given {@link Callable} in the {@link ClassLoader} provided. Return the result, if any.
    */
   public static <T> T executeIn(ClassLoader loader, Callable<T> task) throws Exception
   {
      if (task == null)
         return null;

      if (log.isLoggable(Level.FINE))
      {
         log.fine("ClassLoader [" + loader + "] task began.");
      }
      ClassLoader original = SecurityActions.getContextClassLoader();
      try
      {
         SecurityActions.setContextClassLoader(loader);
         return task.call();
      }
      finally
      {
         SecurityActions.setContextClassLoader(original);
         if (log.isLoggable(Level.FINE))
         {
            log.fine("ClassLoader [" + loader + "] task ended.");
         }
      }
   }

   public static boolean containsClass(ClassLoader loader, Class<?> type)
   {
      if (loader == null)
         throw new IllegalArgumentException("Class loader to inspect must not be null.");
      if (type == null)
         throw new IllegalArgumentException("Class to find must not be null.");

      try
      {
         return loader.loadClass(type.getName()) == type;
      }
      catch (ClassNotFoundException | LinkageError e)
      {
         return false;
      }
   }

   public static boolean containsClass(ClassLoader loader, String type)
   {
      if (loader == null)
         throw new IllegalArgumentException("Class loader to inspect must not be null.");
      if (type == null)
         throw new IllegalArgumentException("Class to find must not be null.");

      try
      {
         loader.loadClass(type);
         return true;
      }
      catch (ClassNotFoundException | LinkageError e)
      {
         return false;
      }
   }

   public static Class<?> loadClass(ClassLoader loader, String typeName)
   {
      if (loader == null)
         throw new IllegalArgumentException("Class loader to inspect must not be null.");
      if (typeName == null)
         throw new IllegalArgumentException("Class name to find must not be null.");

      try
      {
         return loader.loadClass(typeName);
      }
      catch (ClassNotFoundException | LinkageError e)
      {
         throw new ContainerException("Could not locate class [" + typeName + "] in Loader [" + loader + "]", e);
      }
   }

   public static Class<?> loadClass(ClassLoader loader, Class<?> type)
   {
      if (loader == null)
         throw new IllegalArgumentException("Class loader to inspect must not be null.");
      if (type == null)
         throw new IllegalArgumentException("Class to find must not be null.");

      try
      {
         return loader.loadClass(type.getName());
      }
      catch (ClassNotFoundException | LinkageError e)
      {
         throw new ContainerException("Could not locate class [" + type.getName() + "] in Loader [" + loader + "]", e);
      }
   }

   public static boolean ownsClass(ClassLoader loader, Class<?> type)
   {
      if (loader == null)
         throw new IllegalArgumentException("Class loader to inspect must not be null.");
      if (type == null)
         throw new IllegalArgumentException("Class to find must not be null.");

      return loader.equals(type.getClassLoader());
   }
{'fraction_non_alphanumeric': 0.10605256172020175, 'fraction_numerical': 0.0, 'mean_word_length': 2.5160989267382177, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 25, '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': '6745802', 'n_tokens_mistral': 1976, 'n_tokens_neox': 1954, 'n_words': 614}