[jboss-jira] [JBoss JIRA] Created: (JBLOGGING-55) NPE in FileAppender$Helper

Ondrej Zizka (JIRA) jira-events at lists.jboss.org
Tue Feb 8 11:48:46 EST 2011


NPE in FileAppender$Helper
--------------------------

                 Key: JBLOGGING-55
                 URL: https://issues.jboss.org/browse/JBLOGGING-55
             Project: JBoss Logging
          Issue Type: Bug
      Security Level: Public (Everyone can see)
            Reporter: Ondrej Zizka
            Assignee: David Lloyd


When you set the file="..." to just a file, i.e. file="foobar.log", 
then you get a NPE at line
    if (!dir.exists()) {
probably because 
    dir = new File(filename.trim()).getParentFile();
returns null.

I'd expect the appender to write to a file in new File( new File(System.getProperty("user.dir")), filename.trim() ).




package org.jboss.logging.appender;

import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import org.apache.log4j.helpers.LogLog;

public class FileAppender$Helper
{
  public static void makePath(String filename)
  {
    File dir;
    try
    {
      URL url = new URL(filename.trim());
      dir = new File(url.getFile()).getParentFile();
    }
    catch (MalformedURLException e) {
      dir = new File(filename.trim()).getParentFile();
    }

    if (!dir.exists()) {
      boolean success = dir.mkdirs();
      if (!success)
        LogLog.error("Failed to create directory structure: " + dir);
    }
  }
}

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira


More information about the jboss-jira mailing list