
|
If you were logged in you would be able to see more operations.
|
|
|
|
Environment:
|
Windows XP, Sun JRE 1.5
|
|
|
to reproduce:
put an object in the cache that is not a Serializable
hangs in store
The code is:
try {
fout = new FileOutputStream(file);
oout = new ObjectOutputStream(fout);
oout.writeObject(obj);
oout.flush();
} catch (Exception e) {
while (file.exists() && !file.delete()) {
;
}
throw new CachePersistenceException("Unable to write '" + file + "' in the cache. Exception: " + e.getClass().getName() + ", Message: " + e.getMessage());
} finally {
try {
oout.close();
} catch (Exception e) {
try {
fout.close();
} catch (Exception e) {
}
Problem is that in the catch clause when writeObject throws an exception, the code tries to delete the file that is still opened, which can't succeed (at least on XP/JDK 1.5)
Better:
try {
fout = new FileOutputStream(file);
try {
oout = new ObjectOutputStream(fout);
try {
oout.writeObject(obj);
oout.flush();
} finally {
try {
oout.close();
} catch (Exception e) {
}
}
} finally {
try {
fout.close();
} catch (Exception e) {
}
}
} catch (Exception e) {
while (file.exists() && !file.delete()) {
;
}
throw new CachePersistenceException("Unable to write '" + file + "' in the cache. Exception: " + e.getClass().getName() + ", Message: " + e.getMessage());
}
fout needs its own finalize&close because ObjectOutputStream() might throw an exception.
|
|
Description
|
to reproduce:
put an object in the cache that is not a Serializable
hangs in store
The code is:
try {
fout = new FileOutputStream(file);
oout = new ObjectOutputStream(fout);
oout.writeObject(obj);
oout.flush();
} catch (Exception e) {
while (file.exists() && !file.delete()) {
;
}
throw new CachePersistenceException("Unable to write '" + file + "' in the cache. Exception: " + e.getClass().getName() + ", Message: " + e.getMessage());
} finally {
try {
oout.close();
} catch (Exception e) {
try {
fout.close();
} catch (Exception e) {
}
Problem is that in the catch clause when writeObject throws an exception, the code tries to delete the file that is still opened, which can't succeed (at least on XP/JDK 1.5)
Better:
try {
fout = new FileOutputStream(file);
try {
oout = new ObjectOutputStream(fout);
try {
oout.writeObject(obj);
oout.flush();
} finally {
try {
oout.close();
} catch (Exception e) {
}
}
} finally {
try {
fout.close();
} catch (Exception e) {
}
}
} catch (Exception e) {
while (file.exists() && !file.delete()) {
;
}
throw new CachePersistenceException("Unable to write '" + file + "' in the cache. Exception: " + e.getClass().getName() + ", Message: " + e.getMessage());
}
fout needs its own finalize&close because ObjectOutputStream() might throw an exception. |
Show » |
|