Kaydet (Commit) 9501b985 authored tarafından sb's avatar sb

sb120: do not swallow exceptions

üst 487c3b80
......@@ -45,6 +45,7 @@ import com.sun.star.beans.XPropertySet;
import com.sun.star.beans.Property;
import com.sun.star.lang.XMultiServiceFactory;
import com.sun.star.uno.UnoRuntime;
import com.sun.star.ucb.InteractiveAugmentedIOException;
import com.sun.star.ucb.XSimpleFileAccess;
import com.sun.star.lang.XServiceInfo;
......@@ -542,16 +543,10 @@ public class utils {
return res;
}
/**
* Copies file to a new location using OpenOffice.org features. If the target
* file already exists, the file is deleted.
*
* @returns <code>true</code> if the file was successfully copied,
* <code>false</code> if some errors occured (e.g. file is locked, used
* by another process).
*/
public static boolean overwriteFile(XMultiServiceFactory xMsf, String oldF, String newF) {
boolean res = false;
private static void overwriteFile_impl(
XMultiServiceFactory xMsf, String oldF, String newF)
throws InteractiveAugmentedIOException
{
try {
Object fileacc = xMsf.createInstance("com.sun.star.comp.ucb.SimpleFileAccess");
......@@ -561,15 +556,42 @@ public class utils {
simpleAccess.kill(newF);
}
simpleAccess.copy(oldF, newF);
res = true;
} catch (com.sun.star.ucb.InteractiveAugmentedIOException e) {
return false;
} catch (InteractiveAugmentedIOException e) {
throw e;
} catch (com.sun.star.uno.Exception e) {
System.out.println("Couldn't copy " + oldF + " to " + newF + ".");
System.out.println("Couldn't copy " + oldF + " to " + newF + ":");
e.printStackTrace();
throw new RuntimeException(e);
}
}
return res;
/**
* Copies file to a new location using OpenOffice.org features. If the target
* file already exists, the file is deleted.
*
* @returns <code>true</code> if the file was successfully copied,
* <code>false</code> if some errors occured (e.g. file is locked, used
* by another process).
*/
public static boolean tryOverwriteFile(
XMultiServiceFactory xMsf, String oldF, String newF)
{
try {
overwriteFile_impl(xMsf, oldF, newF);
} catch (InteractiveAugmentedIOException e) {
return false;
}
return true;
}
public static void doOverwriteFile(
XMultiServiceFactory xMsf, String oldF, String newF)
{
try {
overwriteFile_impl(xMsf, oldF, newF);
} catch (InteractiveAugmentedIOException e) {
throw new RuntimeException(e);
}
}
public static boolean hasPropertyByName(XPropertySet props, String aName) {
......
......@@ -293,7 +293,7 @@ public class ORowSet extends TestCase {
oldF = utils.getFullURL(origDB);
newF = tempFolder + tableName + ".dbf";
}
while ( !utils.overwriteFile( orb, oldF, newF ) );
while ( !utils.tryOverwriteFile( orb, oldF, newF ) );
m_tableFile = newF;
}
......
......@@ -311,7 +311,7 @@ public class ODatabaseForm extends TestCase {
oldF = utils.getFullURL(origDB);
newF = utils.getOfficeTemp((XMultiServiceFactory) tParam.getMSF()) + tableName +
".dbf";
} while (!utils.overwriteFile(((XMultiServiceFactory) tParam.getMSF()), oldF, newF) &&
} while (!utils.tryOverwriteFile(((XMultiServiceFactory) tParam.getMSF()), oldF, newF) &&
(uniqueSuffix++ < 50));
}
}
......
......@@ -87,7 +87,7 @@ public class StandaloneDocumentInfo extends TestCase {
destUrl = utils.getOfficeTemp((XMultiServiceFactory)tParam.getMSF()) +
"SfxStandaloneDocInfoObject.sdw";
utils.overwriteFile((XMultiServiceFactory)tParam.getMSF(), srcUrl, destUrl) ;
utils.doOverwriteFile((XMultiServiceFactory)tParam.getMSF(), srcUrl, destUrl) ;
}
/**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment