[
https://issues.apache.org/jira/browse/FOP-2857?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Vera Straube updated FOP-2857:
------------------------------
Description:
The java.io.File instance represents a file or directory in the real filesystem.
The function checks only, if the file or directory exists.
I added checks for Nullpointer and if it is a directory.
The function checks the path parameter not strong enough.
I added a check for empty string or a string that contains only whitespaces.
{code:java}
//wrong code
private static File toDirectory(String path) {
if (path != null) {
File dir = new File(path);
if (dir.exists()){
return dir;
}
}
return null;
}
{code}
{code:java}
//correct code
private static File toDirectory(String path) {
if (path != null && !path.trim().isEmpty()) {
//path is a non empty string
File dir = new File(path);
if (dir!=null && dir.exists() && dir.isDirectory()){
//dir exists in the real fileystem and is a directory
return dir;
}
}
return null;
}
{code}
was:
The java.io.File instance represents a file or directory in the real filesystem.
The function checks only, if the file or directory exists.
I added checks for Nullpointer and if it is a directory.
The function checks the path parameter not strong enough.
I added a check for empty string or a string that contains only whitespaces.
{code:java}
//wrong code
private static File toDirectory(String path) {
if (path != null) {
File dir = new File(path);
if (dir.exists()){
return dir;
}
}
return null;
}
{code}
{code:java}
//correct code
private static File toDirectory(String path) {
if (path != null && !path.trim().isEmpty()) {
//path is a non empty string
File dir = new File(path);
if (dir!=null && dir.exists() && dir.isDirectory()){
//dir exists in the real fileystem and is a directory return dir;
}
}
return null;
}
{code}
> FontCache.toDirectory(String path) returns a file object that is not a
> directory
> --------------------------------------------------------------------------------
>
> Key: FOP-2857
> URL: https://issues.apache.org/jira/browse/FOP-2857
> Project: FOP
> Issue Type: Bug
> Components: font/unqualified
> Affects Versions: 2.3
> Reporter: Vera Straube
> Priority: Critical
>
> The java.io.File instance represents a file or directory in the real
> filesystem.
> The function checks only, if the file or directory exists.
> I added checks for Nullpointer and if it is a directory.
> The function checks the path parameter not strong enough.
> I added a check for empty string or a string that contains only whitespaces.
> {code:java}
> //wrong code
> private static File toDirectory(String path) {
> if (path != null) {
> File dir = new File(path);
> if (dir.exists()){
> return dir;
> }
> }
> return null;
> }
> {code}
> {code:java}
> //correct code
> private static File toDirectory(String path) {
> if (path != null && !path.trim().isEmpty()) {
> //path is a non empty string
> File dir = new File(path);
> if (dir!=null && dir.exists() && dir.isDirectory()){
> //dir exists in the real fileystem and is a directory
> return dir;
> }
> }
> return null;
> }
> {code}
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)