On a VMware virtual machine, I am the administrator. On this VM, we are running a batch script that calls Java code. My colleagues are regular users on this VM. The batch script attempts to open the ODS file with the following Java code.
// the boolean property Hidden tells the office to open a file in
// hidden mode
PropertyValue[] props = new PropertyValue[1];
props[0] = new PropertyValue();
props[0].Name = "Hidden";
props[0].Value = new Boolean(true);
XComponent component = xLoader.loadComponentFromURL("file:///" + pathToFile, "_blank", 0, props);
XSpreadsheetDocument document = (XSpreadsheetDocument) UnoRuntime.queryInterface(XSpreadsheetDocument.class, component);
XSpreadsheets sheets = document.getSheets();
The "document" variable is null, which causes a null pointer exception (sometimes, not always) for other users who are not administrators. I have never encountered any issues myself as I am an administrator on the VM.
For your information, xLoader is defined as follows:
XComponentLoader xLoader = initialiseComponent();
and
private XComponentLoader initialiseComponent() {
try {
Object x;
Object defaultContext;
Object desktop;
XComponentContext componentContext = Bootstrap
.createInitialComponentContext(null);
x = componentContext.getServiceManager().createInstanceWithContext(
"com.sun.star.connection.Connector", componentContext);
XConnector connector = (XConnector) UnoRuntime.queryInterface(
XConnector.class, x);
XConnection connection = connector.connect("socket,host="
+ ooService.getConfiguration().getString(
OPEN_OFFICE_HOST_KEY)
+ ",port="
+ ooService.getConfiguration().getString(
OPEN_OFFICE_PORT_KEY));
x = componentContext.getServiceManager().createInstanceWithContext(
"com.sun.star.bridge.BridgeFactory", componentContext);
XBridgeFactory bridgeFactory = (XBridgeFactory) UnoRuntime
.queryInterface(XBridgeFactory.class, x);
XBridge bridge = bridgeFactory.createBridge("", "urp", connection,
null);
x = bridge.getInstance("StarOffice.ServiceManager");
XMultiComponentFactory multiComponentFactory = (XMultiComponentFactory) UnoRuntime
.queryInterface(XMultiComponentFactory.class, x);
XPropertySet properySet = (XPropertySet) UnoRuntime.queryInterface(
XPropertySet.class, multiComponentFactory);
defaultContext = properySet.getPropertyValue("DefaultContext");
componentContext = (XComponentContext) UnoRuntime.queryInterface(
XComponentContext.class, defaultContext);
multiComponentFactory = componentContext.getServiceManager();
desktop = multiComponentFactory.createInstanceWithContext(
"com.sun.star.frame.Desktop", componentContext);
return (XComponentLoader) UnoRuntime.queryInterface(
XComponentLoader.class, desktop);
} catch (java.lang.Exception e) {
log.error(e);
throw new RuntimeException(e);
}
}
Thank you Here are the checks that have already been performed:
- We are using the same classpath.
- User Landa has read and write permissions on the file.
- The file exists at the specified path "file:///" + pathToFile, and when I enter "file:///" + pathToFile, I can access the file.
- The issue is most likely caused by the initializeComponent method.