{"record":{"id":"4fdd48bf074a2294","repo":"stanfordnlp/CoreNLP","slug":"cannot-initialize-logger","errorCode":null,"errorMessage":"Cannot initialize logger!","messagePattern":"Cannot initialize logger!","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/coref/CorefSystem.java","lineNumber":85,"sourceCode":"      CorefUtils.removeSingletonClusters(document);\n    }\n    CorefUtils.checkForInterrupt();\n\n    Map<Integer, CorefChain> result = Generics.newHashMap();\n    for (CorefCluster c : document.corefClusters.values()) {\n      result.put(c.clusterID, new CorefChain(c, document.positions));\n    }\n    ann.set(CorefCoreAnnotations.CorefChainAnnotation.class, result);\n  }\n\n  public void initLogger(Logger logger, String logFileName) {\n      try {\n          FileHandler fh = new FileHandler(logFileName, false);\n          logger.addHandler(fh);\n          logger.setLevel(Level.FINE);\n          fh.setFormatter(new NewlineLogFormatter());\n      } catch (SecurityException | IOException e) {\n          throw new RuntimeException(\"Cannot initialize logger!\", e);\n      }\n  }\n\n  public void runOnConll(Properties props) throws Exception {\n    File f = new File(CorefProperties.conllOutputPath(props));\n    if (! f.exists()) {\n      f.mkdirs();\n    }\n    String timestamp = Calendar.getInstance().getTime().toString().replaceAll(\"\\\\s\", \"-\").replaceAll(\":\", \"-\");\n    String baseName = CorefProperties.conllOutputPath(props) + timestamp;\n    String goldOutput = baseName + \".gold.txt\";\n    String beforeCorefOutput = baseName + \".predicted.txt\";\n    String afterCorefOutput = baseName + \".coref.predicted.txt\";\n    PrintWriter writerGold = new PrintWriter(new FileOutputStream(goldOutput));\n    PrintWriter writerBeforeCoref = new PrintWriter(new FileOutputStream(beforeCorefOutput));\n    PrintWriter writerAfterCoref = new PrintWriter(new FileOutputStream(afterCorefOutput));\n\n    Logger logger = Logger.getLogger(CorefSystem.class.getName());","sourceCodeStart":67,"sourceCodeEnd":103,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/coref/CorefSystem.java#L67-L103","documentation":"CorefSystem.initLogger throws RuntimeException(\"Cannot initialize logger!\") when java.util.logging FileHandler cannot attach a handler to logFileName — a SecurityException (security manager denies file logging) or IOException (path unwritable/invalid).","triggerScenarios":"initLogger called (from runOnConll) with a logFileName in a nonexistent directory, a read-only location, or blocked by a SecurityException from a security manager.","commonSituations":"Log path points to a non-writable directory under the working dir; running in a sandboxed/containerized environment with restricted file access; logFileName containing invalid path characters or a locked file.","solutions":["Set the coref log file property to an absolute path in a writable directory and create parent dirs first","Check file write permissions on the log directory (chmod / run as appropriate user)","If a SecurityManager is active, grant FileHandler permissions or use console logging instead","Wrap or reconfigure java.util.logging to log to stdout in restricted environments"],"exampleFix":"// before\nprops.setProperty(\"coref.logFile\", \"logs/coref.log\"); // logs/ doesn't exist\n// after\nFile logDir = new File(\"/tmp/coref-logs\");\nlogDir.mkdirs();\nprops.setProperty(\"coref.logFile\", new File(logDir, \"coref.log\").getAbsolutePath());","handlingStrategy":"validation","validationCode":"File logFile = new File(logFileName);\nFile parent = logFile.getAbsoluteFile().getParentFile();\nif (parent != null && !parent.isDirectory() && !parent.mkdirs()) {\n  throw new IllegalStateException(\"Cannot create log dir: \" + parent);\n}\nif (!logFile.getParentFile().canWrite()) {\n  throw new IllegalStateException(\"Log dir not writable: \" + parent);\n}","typeGuard":null,"tryCatchPattern":"try {\n  system.runOnConll(props);\n} catch (RuntimeException e) {\n  if (\"Cannot initialize logger!\".equals(e.getMessage())) {\n    logger.log(Level.SEVERE, \"Logger init failed; check log path/permissions\", e.getCause());\n  } else throw e;\n}","preventionTips":["Configure the coref log file to an absolute path in a writable directory","Create parent directories before running","Check for SecurityManager restrictions in the deployment environment","Fall back to console logging in containers/sandboxes"],"tags":["logging","io","file-write","permissions"],"backgroundTag":"file-write-failed","analyzedSha":"1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a","analyzedAt":"2026-09-10T02:24:07.274Z","contentChangedAt":"2026-09-10T02:24:07.274Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}