<commit_before>package com.intellij.diagnostic;

import com.intellij.openapi.application.Application;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.diagnostic.ErrorLogger;
import com.intellij.openapi.diagnostic.IdeaLoggingEvent;
import org.apache.log4j.AppenderSkeleton;
import org.apache.log4j.Priority;
import org.apache.log4j.spi.LoggingEvent;
import org.apache.log4j.spi.ThrowableInformation;

import javax.swing.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @author Mike
 */
public class DialogAppender extends AppenderSkeleton {
  private static final DefaultIdeaErrorLogger DEFAULT_LOGGER = new DefaultIdeaErrorLogger();

  private Runnable myDialogRunnable = null;

  protected synchronized void append(final LoggingEvent event) {
    if (!event.level.isGreaterOrEqual(Priority.ERROR)) return;

    SwingUtilities.invokeLater(new Runnable() {
      public void run() {
        List<ErrorLogger> loggers = new ArrayList<ErrorLogger>();
        loggers.add(DEFAULT_LOGGER);

        Application application = ApplicationManager.getApplication();
        if (application != null) {
          if (application.isHeadlessEnvironment() || application.isDisposed()) return;
          loggers.addAll(Arrays.asList(application.getComponents(ErrorLogger.class)));
        }

        appendToLoggers(event, loggers.toArray(new ErrorLogger[loggers.size()]));
      }
    });
  }

  void appendToLoggers(final LoggingEvent event, ErrorLogger[] errorLoggers) {
    if (myDialogRunnable != null) {
      return;
    }

    ThrowableInformation throwable = event.getThrowableInformation();
    if (throwable == null) {
      return;
    }

    final Object message = event.getMessage();
    final IdeaLoggingEvent ideaEvent = new IdeaLoggingEvent(message == null ? "<null> " : message.toString(), throwable.getThrowable());
    for (int i = errorLoggers.length - 1; i >= 0; i--) {

      final ErrorLogger logger = errorLoggers[i];
      if (logger.canHandle(ideaEvent)) {

        myDialogRunnable = new Runnable() {
          public void run() {
            try {
              logger.handle(ideaEvent);
            }
            finally {
              myDialogRunnable = null;
            }
          }
        };

        ApplicationManager.getApplication().executeOnPooledThread(myDialogRunnable);

        break;
      }
    }
  }

  public boolean requiresLayout() {
    return false;
  }

  public void close() {
  }
}
<commit_msg>AppMgr.getApp() == null in DialogAppender<commit_after>package com.intellij.diagnostic;

import com.intellij.openapi.application.Application;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.diagnostic.ErrorLogger;
import com.intellij.openapi.diagnostic.IdeaLoggingEvent;
import org.apache.log4j.AppenderSkeleton;
import org.apache.log4j.Priority;
import org.apache.log4j.spi.LoggingEvent;
import org.apache.log4j.spi.ThrowableInformation;

import javax.swing.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @author Mike
 */
public class DialogAppender extends AppenderSkeleton {
  private static final DefaultIdeaErrorLogger DEFAULT_LOGGER = new DefaultIdeaErrorLogger();

  private Runnable myDialogRunnable = null;

  protected synchronized void append(final LoggingEvent event) {
    if (!event.level.isGreaterOrEqual(Priority.ERROR)) return;

    SwingUtilities.invokeLater(new Runnable() {
      public void run() {
        List<ErrorLogger> loggers = new ArrayList<ErrorLogger>();
        loggers.add(DEFAULT_LOGGER);

        Application application = ApplicationManager.getApplication();
        if (application != null) {
          if (application.isHeadlessEnvironment() || application.isDisposed()) return;
          loggers.addAll(Arrays.asList(application.getComponents(ErrorLogger.class)));
        }

        appendToLoggers(event, loggers.toArray(new ErrorLogger[loggers.size()]));
      }
    });
  }

  void appendToLoggers(final LoggingEvent event, ErrorLogger[] errorLoggers) {
    if (myDialogRunnable != null) {
      return;
    }

    ThrowableInformation throwable = event.getThrowableInformation();
    if (throwable == null) {
      return;
    }

    final Object message = event.getMessage();
    final IdeaLoggingEvent ideaEvent = new IdeaLoggingEvent(message == null ? "<null> " : message.toString(), throwable.getThrowable());
    for (int i = errorLoggers.length - 1; i >= 0; i--) {

      final ErrorLogger logger = errorLoggers[i];
      if (logger.canHandle(ideaEvent)) {

        myDialogRunnable = new Runnable() {
          public void run() {
            try {
              logger.handle(ideaEvent);
            }
            finally {
              myDialogRunnable = null;
            }
          }
        };

        final Application app = ApplicationManager.getApplication();
        if (app == null) {
          new Thread(myDialogRunnable).start();  
        } else {
          app.executeOnPooledThread(myDialogRunnable);
        }

        break;
      }
    }
  }

  public boolean requiresLayout() {
    return false;
  }

  public void close() {
  }
}

{'fraction_non_alphanumeric': 0.10598191959992306, 'fraction_numerical': 0.002308136180034622, 'mean_word_length': 3.130262112787927, 'pattern_counts': {'":': 0, '<': 9, '<?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': '5525875', 'n_tokens_mistral': 1517, 'n_tokens_neox': 1472, 'n_words': 297}