I am currently working on converting doc to docx files in a java project. I use some lib from com.sun.star that I manage to get working on a previous iteration, but now everything is crashing at the first try of conversion.
My code is :
String sourceUrl = "file:///" + listOfFile[i].getAbsolutePath().replace('\\', fileSeparator);
String targetUrl = "file:///" + listOfFile[i].getAbsolutePath().replace('\\', fileSeparator) + 'x';
// Setup the source file for libreoffice
PropertyValue propertyValue[] = new PropertyValue[1];
propertyValue[0] = new PropertyValue();
propertyValue[0].Name = "Hidden";
propertyValue[0].Value = Boolean.TRUE;
Object oDocToStor = DocConverter.xCompLoader.loadComponentFromURL(sourceUrl, "_blank", 0, propertyValue);
XStorable xStorable = UnoRuntime.queryInterface(XStorable.class, oDocToStor);
// Setting up the converter by giving him the source file qnd the tqrget type
propertyValue = new PropertyValue[2];
propertyValue[0] = new PropertyValue();
propertyValue[0].Name = "Overwrite";
propertyValue[0].Value = Boolean.TRUE;
propertyValue[1] = new PropertyValue();
propertyValue[1].Name = "FilterName";
propertyValue[1].Value = "MS Word 2007 XML";
// Apply convertion !!! It crash at this step !!!
xStorable.storeAsURL(targetUrl, propertyValue);
XCloseable xCloseable = UnoRuntime.queryInterface(XCloseable.class, xStorable);
if (xCloseable != null) {
xCloseable.close();
} else {
XComponent xComp = UnoRuntime.queryInterface(XComponent.class, xStorable);
xComp.dispose();
}
and I get the following exception :
java.lang.AssertionError: com.sun.star.task.ErrorCodeIOException: SfxBaseModel::impl_store <file:///D:\my\file.docx> failed: 0x31c
at org.junit.Assert.fail(Assert.java:93)
at fr.gouv.travail.utils.service.impl.DocConverterTest.testDirectory(DocConverterTest.java:67)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:75)
at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:86)
at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:84)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:254)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:89)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
at org.junit.runners.ParentRunner.run(ParentRunner.java:292)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:193)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:678)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
When I launch it the second time, I get a null pointer exception since the first iteration do not free ressource in libreoffice and can not open them again.
My socket looks correctly opened, my file are in the rigth place since I target a entire non empty directory and coworker do not get the error too.
edit : I check all write permission in my folder and everything is fine.
Thanks in advance for the help :)