<commit_before>package com.novocode.junit

import sbt.testing._

import scala.collection.mutable

import Ansi._

final class RichLogger private (loggers: Array[Logger], settings: RunSettings) {

  private[this] val currentTestClassName = new mutable.Stack[String]()

  def this(loggers: Array[Logger], settings: RunSettings,
      testClassName: String) = {
    this(loggers, settings)
    currentTestClassName.push(testClassName)
  }

  def pushCurrentTestClassName(s: String): Unit =
    currentTestClassName.push(s)

  def popCurrentTestClassName(): Unit = {
    if (currentTestClassName.size > 1)
      currentTestClassName.pop()
  }

  def debug(s: String): Unit = {
    for (l <- loggers)
      l.debug(filterAnsiIfNeeded(l, s))
  }

  def error(s: String): Unit = {
    for (l <- loggers)
      l.error(filterAnsiIfNeeded(l, s))
  }

  def error(s: String, t: Throwable): Unit = {
    error(s)
    if (t != null && (settings.logAssert || !t.isInstanceOf[AssertionError]))
      logStackTrace(t)
  }

  def info(s: String): Unit = {
    for (l <- loggers)
      l.info(filterAnsiIfNeeded(l, s))
  }

  def warn(s: String): Unit = {
    for (l <- loggers)
      l.warn(filterAnsiIfNeeded(l, s))
  }

  private def filterAnsiIfNeeded(l: Logger, s: String): String =
    if (l.ansiCodesSupported() && settings.color) s
    else filterAnsi(s)

  private def logStackTrace(t: Throwable): Unit = {
    val trace = t.getStackTrace.dropWhile { p =>
      p.getFileName.contains("StackTrace.scala") ||
      p.getFileName.contains("Throwables.scala")
    }
    val testClassName = currentTestClassName.head
    val testFileName = {
      if (settings.color) findTestFileName(trace, testClassName)
      else null
    }
    val i = trace.indexWhere(p => p.getFileName.contains("JUnitExecuteTest.scala")) - 1
    val m = if (i > 0) i else trace.length - 1
    logStackTracePart(trace, m, trace.length - m - 1, t, testClassName, testFileName)
  }

  private def logStackTracePart(trace: Array[StackTraceElement], m: Int,
      framesInCommon: Int, t: Throwable, testClassName: String,<commit_msg>Fix #2152: Make JUnit's RichLogger tolerant to null getFileName.<commit_after>package com.novocode.junit

import sbt.testing._

import scala.collection.mutable

import Ansi._

final class RichLogger private (loggers: Array[Logger], settings: RunSettings) {

  private[this] val currentTestClassName = new mutable.Stack[String]()

  def this(loggers: Array[Logger], settings: RunSettings,
      testClassName: String) = {
    this(loggers, settings)
    currentTestClassName.push(testClassName)
  }

  def pushCurrentTestClassName(s: String): Unit =
    currentTestClassName.push(s)

  def popCurrentTestClassName(): Unit = {
    if (currentTestClassName.size > 1)
      currentTestClassName.pop()
  }

  def debug(s: String): Unit = {
    for (l <- loggers)
      l.debug(filterAnsiIfNeeded(l, s))
  }

  def error(s: String): Unit = {
    for (l <- loggers)
      l.error(filterAnsiIfNeeded(l, s))
  }

  def error(s: String, t: Throwable): Unit = {
    error(s)
    if (t != null && (settings.logAssert || !t.isInstanceOf[AssertionError]))
      logStackTrace(t)
  }

  def info(s: String): Unit = {
    for (l <- loggers)
      l.info(filterAnsiIfNeeded(l, s))
  }

  def warn(s: String): Unit = {
    for (l <- loggers)
      l.warn(filterAnsiIfNeeded(l, s))
  }

  private def filterAnsiIfNeeded(l: Logger, s: String): String =
    if (l.ansiCodesSupported() && settings.color) s
    else filterAnsi(s)

  private def logStackTrace(t: Throwable): Unit = {
    val trace = t.getStackTrace.dropWhile { p =>
      p.getFileName != null && {
        p.getFileName.contains("StackTrace.scala") ||
        p.getFileName.contains("Throwables.scala")
      }
    }
    val testClassName = currentTestClassName.head
    val testFileName = {
      if (settings.color) findTestFileName(trace, testClassName)
      else null
    }
    val i = trace.indexWhere {
      p => p.getFileName != null && p.getFileName.contains("JUnitExecuteTest.scala")
    } - 1
    val m = if (i > 0) i else trace.length - 1
    logStackTracePart(trace, m, trace.length - m - 1, t, testClassName, testFileName)
  }

  private def logStackTracePart(trace: Array[StackTraceElement], m: Int,
      framesInCommon: Int, t: Throwable, testClassName: String,
{'fraction_non_alphanumeric': 0.12517385257301808, 'fraction_numerical': 0.003245248029670839, 'mean_word_length': 3.389623601220753, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, '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': '3834425', 'n_tokens_mistral': 1435, 'n_tokens_neox': 1386, 'n_words': 334}