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

James Perkins (JIRA) issues at jboss.org
Sat Nov 8 11:12:30 EST 2014


     [ https://issues.jboss.org/browse/JBLOGGING-55?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

James Perkins closed JBLOGGING-55.
----------------------------------


> NPE in FileAppender$Helper
> --------------------------
>
>                 Key: JBLOGGING-55
>                 URL: https://issues.jboss.org/browse/JBLOGGING-55
>             Project: JBoss Logging
>          Issue Type: Bug
>            Reporter: Ondrej Zizka
>            Assignee: David Lloyd
>         Attachments: log4j.xml
>
>
> 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 was sent by Atlassian JIRA
(v6.3.8#6338)


More information about the jboss-jira mailing list