This code is from a library that I use and I decompiled because of an error.
On Windows 32 it works correctly if the user that launches the program is an administrator of the machine, otherwise it crashes. On linux it crashes too.
/* */ public static String cambiaEstensione(String nomeFile, String nuovaEstensione)
/* */ {
/* 140 */ int p = nomeFile.lastIndexOf('.');
/* 141 */ if (p < 0) {
/* 142 */ return nomeFile + "." + nuovaEstensione;
/* */ }
/* 144 */ return nomeFile.substring(0, p) + "." + nuovaEstensione;
/* */ }
The caller of the function is this:
/* 182 */ if (this.fl_scrivi) {
/* 183 */ stato = "Apertura archivio dichiarazioni da inviare...";
/* 184 */ this.dcm = new Dcm();
/* 185 */ this.dcm.setNomeDcm(Util.cambiaEstensione(args[2], "dcm"));
/* 186 */ this.dcm.setFileDcm(new FileOutputStream(this.dcm.getNomeDcm()));
/* */ }
The exception is:
java.io.FileNotFoundException: .dcm (Accesso negato)
at java.io.FileOutputStream.open(Native Method)
at java.io.FileOutputStream.<init>(Unknown Source)
at java.io.FileOutputStream.<init>(Unknown Source)
at it.finanze.entrate.sco.main.M77S11.elaboraFile(M77S11.java:186)
Where “Accesso negato” means “Access Denied“.
Can you help me to understand the reason of the error?
UPDATE: The reason of the problem was that I was passing an empty string in args[2].
On Windows with administrator privileges it did not crash because it created the file C:\.dcm, not sure if I have to consider that a feature or a bug.
Thank you very much to everybody who answered.
It’s right there in the stack trace.
It can’t find a file named “.dcm” so it seems:
Either the calling function passed an empty string for the filename, in other words args[2] returns an empty string at this line
OR (since this occurs on Linux) args[2] contains a value like “.something” so this line
Returns zero and then this line
Returns just empty string + “.” + extension. (i.e. “.dcm”)
Linux uses “.filename” to denote hidden files