<commit_before>package org.corpus_tools.annis.gui;

import com.auth0.jwt.JWT;
import com.auth0.jwt.algorithms.Algorithm;
import com.moandjiezana.toml.TomlWriter;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Desktop;
import java.awt.Dimension;
import java.awt.Image;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.time.Instant;
import java.time.temporal.ChronoUnit;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import javax.imageio.ImageIO;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
import javax.swing.plaf.nimbus.NimbusLookAndFeel;
import org.apache.commons.lang3.RandomStringUtils;
import org.corpus_tools.annis.gui.security.SecurityConfiguration;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.context.annotation.Profile;
import org.springframework.core.env.Environment;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.oauth2.core.oidc.OidcIdToken;
import org.springframework.security.oauth2.core.oidc.user.DefaultOidcUser;
import org.springframework.stereotype.Component;
import org.tomlj.Toml;
import org.tomlj.TomlArray;
import org.tomlj.TomlParseResult;
import org.tomlj.TomlTable;

@Component
@Profile("desktop")
public class ServiceStarterDesktop extends ServiceStarter { // NO_UCD (unused code)

  private static final String USER_NAME = "desktop";
  private static final Logger log = LoggerFactory.getLogger(ServiceStarterDesktop.class);
  private final String secret = RandomStringUtils.randomAlphanumeric(50);
  private Optional<UsernamePasswordAuthenticationToken> desktopUserCredentials = Optional.empty();


  @Value("${server.port}")
  private String serverPort;

  @Autowired
  private Environment env;

  private List<Object> unpackToml(TomlArray orig) {
    if (orig == null) {
      return null;
    }
    ArrayList<Object> result = new ArrayList<>(orig.size());

    for (Object o : orig.toList()) {
      if (o instanceof TomlArray) {
        TomlArray tomlArray = (TomlArray) o;
        result.add(unpackToml(tomlArray));
      } else if (o instanceof TomlTable) {
        TomlTable tomlTable = (TomlTable) o;
        result.add(unpackToml(tomlTable));
      } else {
        result.add(o);
      }
    }

    return result;
  }

  private Map<String, Object> unpackToml(TomlTable orig) {
    if (orig == null) {
      return null;
    }

    LinkedHashMap<String, Object> result = new LinkedHashMap<>();

    for (Map.Entry<String, Object> e : orig.toMap().entrySet()) {
      if(e.getValue() instanceof TomlArray) {
        TomlArray tomlArray = (TomlArray) e.getValue();
        result.put(e.getKey(), unpackToml(tomlArray));
      } else if (e.getValue() instanceof TomlTable) {
        TomlTable tomlTable = (TomlTable) e.getValue();
        result.put(e.getKey(), unpackToml(tomlTable));
      } else {
        result.put(e.getKey(), e.getValue());
      }
    }
    
    return result;
  }

  /**
   * Overwrite the existing configuration file and add a temporary user for the desktop.
   */
  @Override
  protected File getServiceConfig() throws IOException {
    TomlParseResult tomlConfig = Toml.parse(super.getServiceConfig().toPath());
    Map<String, Object> config = unpackToml(tomlConfig);

    // Add it to the configuration
    Map<String, Object> tokenVerification = new LinkedHashMap<>();
    tokenVerification.put("type", "HS256");
    tokenVerification.put("secret", this.secret);<commit_msg>Avoid null pointer exception<commit_after>package org.corpus_tools.annis.gui;

import com.auth0.jwt.JWT;
import com.auth0.jwt.algorithms.Algorithm;
import com.moandjiezana.toml.TomlWriter;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Desktop;
import java.awt.Dimension;
import java.awt.Image;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.time.Instant;
import java.time.temporal.ChronoUnit;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import javax.imageio.ImageIO;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
import javax.swing.plaf.nimbus.NimbusLookAndFeel;
import org.apache.commons.lang3.RandomStringUtils;
import org.corpus_tools.annis.gui.security.SecurityConfiguration;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.context.annotation.Profile;
import org.springframework.core.env.Environment;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.oauth2.core.oidc.OidcIdToken;
import org.springframework.security.oauth2.core.oidc.user.DefaultOidcUser;
import org.springframework.stereotype.Component;
import org.tomlj.Toml;
import org.tomlj.TomlArray;
import org.tomlj.TomlParseResult;
import org.tomlj.TomlTable;

@Component
@Profile("desktop")
public class ServiceStarterDesktop extends ServiceStarter { // NO_UCD (unused code)

  private static final String USER_NAME = "desktop";
  private static final Logger log = LoggerFactory.getLogger(ServiceStarterDesktop.class);
  private final String secret = RandomStringUtils.randomAlphanumeric(50);
  private Optional<UsernamePasswordAuthenticationToken> desktopUserCredentials = Optional.empty();


  @Value("${server.port}")
  private String serverPort;

  @Autowired
  private Environment env;

  private List<Object> unpackToml(TomlArray orig) {
    if (orig == null) {
      return null;
    }
    ArrayList<Object> result = new ArrayList<>(orig.size());

    for (Object o : orig.toList()) {
      if (o instanceof TomlArray) {
        TomlArray tomlArray = (TomlArray) o;
        result.add(unpackToml(tomlArray));
      } else if (o instanceof TomlTable) {
        TomlTable tomlTable = (TomlTable) o;
        result.add(unpackToml(tomlTable));
      } else {
        result.add(o);
      }
    }

    return result;
  }

  private Map<String, Object> unpackToml(TomlTable orig) {
    if (orig == null) {
      return null;
    }

    LinkedHashMap<String, Object> result = new LinkedHashMap<>();

    for (Map.Entry<String, Object> e : orig.toMap().entrySet()) {
      if(e.getValue() instanceof TomlArray) {
        TomlArray tomlArray = (TomlArray) e.getValue();
        result.put(e.getKey(), unpackToml(tomlArray));
      } else if (e.getValue() instanceof TomlTable) {
        TomlTable tomlTable = (TomlTable) e.getValue();
        result.put(e.getKey(), unpackToml(tomlTable));
      } else {
        result.put(e.getKey(), e.getValue());
      }
    }
    
    return result;
  }

  /**
   * Overwrite the existing configuration file and add a temporary user for the desktop.
   */
  @Override
  protected File getServiceConfig() throws IOException {
    TomlParseResult tomlConfig = Toml.parse(super.getServiceConfig().toPath());
    Map<String, Object> config = unpackToml(tomlConfig);
    if (config == null) {
      config = new LinkedHashMap<>();
    }

    // Add it to the configuration
    Map<String, Object> tokenVerification = new LinkedHashMap<>();
    tokenVerification.put("type", "HS256");
    tokenVerification.put("secret", this.secret);
{'fraction_non_alphanumeric': 0.1114916735561592, 'fraction_numerical': 0.0028345340734616748, 'mean_word_length': 4.477360931435964, 'pattern_counts': {'":': 0, '<': 26, '<?xml version=': 0, '>': 26, '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': '6988010', 'n_tokens_mistral': 2585, 'n_tokens_neox': 2573, 'n_words': 536}