-
Bug
-
Resolution: Duplicate
-
P5
-
None
-
12, 13, 14
-
x86_64
-
windows_10
A DESCRIPTION OF THE PROBLEM :
As per source:
public boolean renameTo(File dest) {
SecurityManager security = System.getSecurityManager();
if (security != null) {
security.checkWrite(path);
security.checkWrite(dest.path);
}
if (dest == null) {
throw new NullPointerException();
}
if (this.isInvalid() || dest.isInvalid()) {
return false;
}
return fs.rename(this, dest);
}
Only after dest.path is accessed is desc compared to null, causing a NPE before the expected place.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Call File.renameTo on any file with a null argument.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
A NullPointerException should be thrown from the throw clause.
ACTUAL -
A NPE was thrown due to a null argument in the call security.checkWrite(dest.path).
---------- BEGIN SOURCE ----------
package bug;
import java.io.File;
public class Main{
public static void main(String...args){
new File("C:"+File.separator+"temp").renameTo(null);
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
None.
FREQUENCY : always
As per source:
public boolean renameTo(File dest) {
SecurityManager security = System.getSecurityManager();
if (security != null) {
security.checkWrite(path);
security.checkWrite(dest.path);
}
if (dest == null) {
throw new NullPointerException();
}
if (this.isInvalid() || dest.isInvalid()) {
return false;
}
return fs.rename(this, dest);
}
Only after dest.path is accessed is desc compared to null, causing a NPE before the expected place.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Call File.renameTo on any file with a null argument.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
A NullPointerException should be thrown from the throw clause.
ACTUAL -
A NPE was thrown due to a null argument in the call security.checkWrite(dest.path).
---------- BEGIN SOURCE ----------
package bug;
import java.io.File;
public class Main{
public static void main(String...args){
new File("C:"+File.separator+"temp").renameTo(null);
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
None.
FREQUENCY : always
- duplicates
-
JDK-8216172 File.renameTo(File dest) should check for NPE at the very beginning
- Closed