On 06.03.2014 19:05, Steele, Raymond wrote:

I was able to overcome this by making the following changes. Basically, I used XNameAcess to access the sheet and created a new object each time that I needed a new sheet within the workbook. I am not sure why it works, but it does now.

Now, in a different area of code, I am getting DisposedExceptions again. I have a for loop that uses loadComponentFromURL to load, export as PDF, and close the document each iteration. I do a desktop.terminate when the loop completes and get the XMultiCOmponentFactory and XComponentLoader before the loop executes.


Where is the DisposedException being triggered?

I noticed a possible problem in closeDocument() (I can't be sure, there are a couple of syntax errors (mostly lowe/upper case errors of single characters; code looks like printed out and scanned in again)):

the else part of the outer if statement is only executed when model==null. The queryInterface to XComponent is OK, but the following dispose would throw a NullPointerException.

-Andre

*public**class*_Load_ {

String master_track_dir= System./getenv/("PLN_MASTER_TRK");

String restore_track= master_track_dir+ "/RAYMOND/restore_track.xml";

String master_track= master_track_dir+ "/RAYMOND/track.xml";

*public*Load() {

       }

*public**static*_main(String[] args)_ {

*try*{

Load block = *new*Load();

_XComponentContext_ context = _Bootstarp_.bootstrap();

*if*(context == *null*) {

System.err.println("ERROR: Could not bootstrap default Office");

System.exit(1);

}

_XMultiComponentFactory_ component_factory = context.getServiceManager();

*try*{

Object desktop = component_factory.createInstanceWithContext("com.sun.star.frame.Desktop", context);

_XComponentLoader_ xComponentLoader = _UnoRuntime_.queryInterface(_XComponentLoader_.*class*, desktop);

_PropertyValue_ loadProps= *new*_PropertyValue_[1];

loadProps[0] = *new*_PropertyValue_();

loadProps[0].Name = "Hidden";

loadProps[0].Value = Boolean.FALSE;

String odsFile = System.getenv("PLN_DAT_GCFILES") + "/Track.ods";

*new*_File_(odsFile).delete();

_DocumentHandler_ otsHandler = *new*_DocumentHandler_();

String otsFile = "/tmp/Track.ots";

String otsUrl = otsHandler.convertFilePathToURL(otsFile);

String odsUrl = otsHandler.convertFilePathToURL(odsFile);

//Load ._ots_ file, opens "Untitled 1._ods_"

_XComponent_ otsComponent = _XComponentLoader_.loadComponent.loadComponentFromURL(otsUrl, "_blank", 0, loadProps);

//export "Untitled 1" as /_tmp_/Track.ods file

block.exportDocumentAs(otsComponent, odsFile, _DocumentHAndler_.DocumentSaveFormat.SCALC, Boolean.TRUE, "1");

//close "Untitled 1._ods_"

block.closeDocument(otsComponent);

//Open /_tmp_/Track.ods

_XComponent_ odsComponent = _XComponentLoader_.loadComponentFromURL(odsUrl, "_blank", 0, loadProps);

String track = *null*;

*if*(*new*_File_(block.restore_track).exists()){

track = block.restore_track;

} *else*{

track = block.master_track;

}

_XSpreadsheetDocument_ doc = _UnoRuntime_.queryInterface(_XspreadsheetDocument_.*class*, odsComponent);

_XSpreadsheets_ sheets = doc.getSheets();

//Object sheetObj = *null*;

//_XSpreadsheet_ sheet = *null*;

//_XCellRange_ cells = *null*;

//_XCellRange_ range = *null*;

//_XCellRangeData_ data = *null*;

//Object[][] data_obj = *null*;

XNameAcess sheetNA = _UnoRuntime_.queryInterface(_XspreadsheetDocument_.*class*, sheets);

Object sheetObj1 = sheetNA.getByName("Dest Data");

XSpreadsheet sheet1 = _UnoRuntime_.queryInterface(_XspreadsheetDocument_.*class*, sheetObj1);

//Populate worksheet

//sheetObj = sheets.getByName("Dest Data");

//sheet = _UnoRuntime_.queryInterface(_XSpreadsheet_.*class*, sheetObj1);

XCellRange cells1= _UnoRuntime_.queryInterface(_XCellRange_.*class*, sheet1);

XCellRange range1= cells1.getCellRangeByName("A2:E100");

XCellRangeData data1= _UnoRuntime_.queryInterface(_XCellRangeData_.*class*, range1);

Object[][] data_obj1= data1.getDataArray();

//Populate data_obj here..... This part omitted for clarity an need to manually type.

data1.setDataArray(data_obj1);

XNameAcess sheetNA2 = _UnoRuntime_.queryInterface(_XspreadsheetDocument_.*class*, sheets);

Object sheetObj2 = sheetNA2.getByName("Emer Data");

XSpreadsheet sheet2 = _UnoRuntime_.queryInterface(_XspreadsheetDocument_.*class*, sheetObj2);

//Populate worksheet

//sheetObj = sheets.getByName("Emer Data");

//sheet = _UnoRuntime_.queryInterface(_XSpreadsheet_.*class*, sheetObj);

XCellRange cells2 = _UnoRuntime_.queryInterface(_XCellRange_.*class*, sheet2);

XCellRange range2 = cells2.getCellRangeByName("A2:F17");

XCellRangeData data2 = _UnoRuntime_.queryInterface(_XCellRangeData_.*class*, range2);

Object[][] data_obj2= data2.getDataArray();

//Populate data_obj here..... This part omitted for clarity an need to manually type.

data2.setDataArray(data_obj2);

//Populate worksheet

XNameAcess sheetNA3 = _UnoRuntime_.queryInterface(_XspreadsheetDocument_.*class*, sheets);

Object sheetObj3 = sheetNA3.getByName("Oper Data");

XSpreadsheet sheet3 = _UnoRuntime_.queryInterface(_XspreadsheetDocument_.*class*, sheetObj3);

//sheetObj = sheets.getByName("Oper Data");

//**************** com.sun.star.lang.DisposedException occurs here.************************//

  //sheet = _UnoRuntime_.queryInterface(_XSpreadsheet_.class, sheetObj);

XCellRange cells3 = _UnoRuntime_.queryInterface(_XCellRange_.*class*, sheet3);

XCellRange range3 = cells3.getCellRangeByName("A2:E11");

XCellRangeData data3 = _UnoRuntime_.queryInterface(_XCellRangeData_.*class*, range3);

Object[][] data_obj3 = data3.getDataArray();

//Populate data_obj here..... This part omitted for clarity an need to manually type.

data3.setDataArray(data_obj3);

//Populate worksheet

XNameAcess sheetNA4 = _UnoRuntime_.queryInterface(_XspreadsheetDocument_.*class*, sheets);

Object sheetObj4 = sheetNA4.getByName("Param Data");

XSpreadsheet sheet4 = _UnoRuntime_.queryInterface(_XspreadsheetDocument_.*class*, sheetObj4);

//sheetObj = sheets.getByName("Param Data");

//sheet = _UnoRuntime_.queryInterface(_XSpreadsheet_.*class*, sheetObj);

XCellRange cells4 = _UnoRuntime_.queryInterface(_XCellRange_.*class*, sheet4);

XCellRange range4 = cells.getCellRangeByName("A2:AW2);

XCellRangeData data4 = _UnoRuntime_.queryInterface(_XCellRangeData_.*class*, range4);

Object[][] data_obj4 = data4.getDataArray();

//Populate data_obj here..... This part omitted for clarity an need to manually type.

data4.setDataArray(data_obj4);

//Populate worksheet

XNameAcess sheetNA5 = _UnoRuntime_.queryInterface(_XspreadsheetDocument_.*class*, sheets);

Object sheetObj5 = sheetNA5.getByName("Point Data");

XSpreadsheet sheet5 = _UnoRuntime_.queryInterface(_XspreadsheetDocument_.*class*, sheetObj5);

//sheetObj = sheets.getByName("Point Data");

//sheet = _UnoRuntime_.queryInterface(_XSpreadsheet_.*class*, sheetObj);

XCellRange cells5 = _UnoRuntime_.queryInterface(_XCellRange_.*class*, sheet5);

XCellRange range5 = cells5.getCellRangeByName("A2:AJ151");

XCellRangeData data5 = _UnoRuntime_.queryInterface(_XCellRangeData_.*class*, range5);

Object[][] data_obj5 = data5.getDataArray();

//Populate data_obj here..... This part omitted for clarity an need to manually type.

data5.setDataArray(data_obj5);

} *catch*(_com.sun.star_.uno.Exception ex) {

System.err.println(ex.getMessage());

} *finally*{

System.exit(1);

}

_}_

       }

*public**void*closeDocument(_XComponent_ document) {

_XModel_ model = _UnoRuntime_.queryInterface(_XModel_.*class*, document);

*if*(model != *null*) {

_XCloseable_ closeable = _UnoRuntime_.queryInterface(_XCloseable_.*class*, model);

*if*(closeable != *null*) {

*try*{

closeable.close(*false*);

} *catch*(_CloseVetoException_ ex) {

System./out/.println(ex.getMessage());

}

}

} *else*{

_XComponent_ disposeable = _UnoRuntime_.queryInterface(_XCompnent_.*class*, model);

disposeable.dispose();

}

       }

*public**void*ExportDocumentAs(_XComponent_ doc, String save_file, _DocumentHandler_.DocumentSaveFormat format, *boolean*overwrite, String page_range) {

*if*((save_file == *null*) || (save_file.trim().length()) == 0) {

*return*;

}

*if*(!overwrite) {

_File_ sfile = *new*_File_(save_file);

*if*(sfile.exists()) {

*throw**new*Exception("File exists");

}

}

_DocumentHandler_ = *new*_DocumentHandler_();

String file_url = _handler_.convertFIlePAthToUrl(save_file);

_XStoreable_ store = _UnoRuntime_.queryInterface(_XStoreable_.*class*, doc);

_PropertyValue_ filter_data= *new*_PropertyValue_[1];

_loadProps_[0] = *new*_PropertyValue_();

_loadProps_[0].Name = "PageRange";

_loadProps_[0].Value = page_range;

_PropertyValue_ loadProps= *new*_PropertyValue_[2];

loadProps[0] = *new*_PropertyValue_();

loadProps[0].Name = "FilterName";

loadProps[0].Value = format.getFormatCode;

loadProps[1] = *new*_PropertyValue_();

loadProps[1].Name = "FilterData";

loadProps[1].Value = filter_data;

store.storeToUrl(file_url, loadProps);

}

}

*From:*Andre Fischer [mailto:awf....@gmail.com]
*Sent:* Thursday, March 06, 2014 1:24 AM
*To:* Steele, Raymond; Andre Fischer; api@openoffice.apache.org
*Subject:* Re: EXTERNAL: Re: DisposedException

On 28.02.2014 20:35, Steele, Raymond wrote:

    I am still having issues. I've typed (there may be typos) out most
    of the code. The following code will fail during runtime on the
    line bolded below. Can anyone identify why? Any help would be great!!!


Sorry for the late reply, I am still not scanning api@ every day and my thunderbird did not update the count of new mails automatically.

I don't see any obvious error in your Java code. I also looked into the C++ implementation of ScTableSheetObj and did not find anything obvious either. The only thing that I can do is to debug the C++ side of the problem, but only if you can send me a running version of your extension, stripped down to the minimum to reproduce this bug.

The only alternative to that (if you can not provide the extension) then we have to rely on collecting more data:

- add an XEventListener to sheets and possibly to doc right after the

_XSpreadsheets_ sheets = doc.getSheets();

line and see if the disposing() method of the listener is called.

- when the DisposedException is thrown, then look at its Source member (should be sheetObj). I don't expect any surprises there but the check doesn't take long.

I am sorry that I can not be of more help.

-Andre


Basically, I am just trying to populate an .ods file's worksheets with data.

*public**class*_Load_ {

String master_track_dir= System./getenv/("PLN_MASTER_TRK");

String restore_track= master_track_dir+ "/RAYMOND/restore_track.xml";

String master_track= master_track_dir+ "/RAYMOND/track.xml";

*public*Load() {

       }

*public**static*_main(String[] args)_ {

*try*{

Load block = *new*Load();

_XComponentContext_ context = _Bootstarp_.bootstrap();

*if*(context == *null*) {

System.err.println("ERROR: Could not bootstrap default Office");

System.exit(1);

}

_XMultiComponentFactory_ component_factory = context.getServiceManager();

*try*{

Object desktop = component_factory.createInstanceWithContext("com.sun.star.frame.Desktop", context);

_XComponentLoader_ xComponentLoader = _UnoRuntime_.queryInterface(_XComponentLoader_.*class*, desktop);

_PropertyValue_ loadProps= *new*_PropertyValue_[1];

loadProps[0] = *new*_PropertyValue_();

loadProps[0].Name = "Hidden";

loadProps[0].Value = Boolean.FALSE;

String odsFile = System.getenv("PLN_DAT_GCFILES") + "/Track.ods";

*new*_File_(odsFile).delete();

_DocumentHandler_ otsHandler = *new*_DocumentHandler_();

String otsFile = "/tmp/Track.ots";

String otsUrl = otsHandler.convertFilePathToURL(otsFile);

String odsUrl = otsHandler.convertFilePathToURL(odsFile);

//Load ._ots_ file, opens "Untitled 1._ods_"

_XComponent_ otsComponent = _XComponentLoader_.loadComponent.loadComponentFromURL(otsUrl, "_blank", 0, loadProps);

//export "Untitled 1" as /_tmp_/Track.ods file

block.exportDocumentAs(otsComponent, odsFile, _DocumentHAndler_.DocumentSaveFormat.SCALC, Boolean.TRUE, "1");

//close "Untitled 1._ods_"

block.closeDocument(otsComponent);

//Open /_tmp_/Track.ods

_XComponent_ odsComponent = _XComponentLoader_.loadComponentFromURL(odsUrl, "_blank", 0, loadProps);

String track = *null*;

*if*(*new*_File_(block.restore_track).exists()){

track = block.restore_track;

} *else*{

track = block.master_track;

}

_XSpreadsheetDocument_ doc = _UnoRuntime_.queryInterface(_XspreadsheetDocument_.*class*, odsComponent);

_XSpreadsheets_ sheets = doc.getSheets();

Object sheetObj = *null*;

_XSpreadsheet_ sheet = *null*;

_XCellRange_ cells = *null*;

_XCellRange_ range = *null*;

_XCellRangeData_ data = *null*;

Object[][] data_obj = *null*;

//Populate worksheet

sheetObj = sheets.getByName("Dest Data");

sheet = _UnoRuntime_.queryInterface(_XSpreadsheet_.*class*, sheetObj);

cells = _UnoRuntime_.queryInterface(_XCellRange_.*class*, sheet);

range = cells.getCellRangeByName("A2:E100");

data = _UnoRuntime_.queryInterface(_XCellRangeData_.*class*, range);

data_obj = data.getDataArray();

//Populate data_obj here..... This part omitted for clarity an need to manually type.

data.setDataArray(data_obj);

//Populate worksheet

sheetObj = sheets.getByName("Emer Data");

sheet = _UnoRuntime_.queryInterface(_XSpreadsheet_.*class*, sheetObj);

cells = _UnoRuntime_.queryInterface(_XCellRange_.*class*, sheet);

range = cells.getCellRangeByName("A2:F17");

data = _UnoRuntime_.queryInterface(_XCellRangeData_.*class*, range);

data_obj = data.getDataArray();

//Populate data_obj here..... This part omitted for clarity an need to manually type.

data.setDataArray(data_obj);

//Populate worksheet

sheetObj = sheets.getByName("Oper Data");

*//**************** com.sun.star.lang.DisposedException occurs here.************************//*

*sheet = _UnoRuntime_.queryInterface(_XSpreadsheet_.**class**, sheetObj);*

cells = _UnoRuntime_.queryInterface(_XCellRange_.*class*, sheet);

range = cells.getCellRangeByName("A2:E11");

data = _UnoRuntime_.queryInterface(_XCellRangeData_.*class*, range);

data_obj = data.getDataArray();

//Populate data_obj here..... This part omitted for clarity an need to manually type.

data.setDataArray(data_obj);

//Populate worksheet

sheetObj = sheets.getByName("Param Data");

sheet = _UnoRuntime_.queryInterface(_XSpreadsheet_.*class*, sheetObj);

cells = _UnoRuntime_.queryInterface(_XCellRange_.*class*, sheet);

range = cells.getCellRangeByName("A2:AW2");

data = _UnoRuntime_.queryInterface(_XCellRangeData_.*class*, range);

data_obj = data.getDataArray();

//Populate data_obj here..... This part omitted for clarity an need to manually type.

data.setDataArray(data_obj);

//Populate worksheet

sheetObj = sheets.getByName("Point Data");

sheet = _UnoRuntime_.queryInterface(_XSpreadsheet_.*class*, sheetObj);

cells = _UnoRuntime_.queryInterface(_XCellRange_.*class*, sheet);

range = cells.getCellRangeByName("A2:AJ151");

data = _UnoRuntime_.queryInterface(_XCellRangeData_.*class*, range);

data_obj = data.getDataArray();

//Populate data_obj here..... This part omitted for clarity an need to manually type.

data.setDataArray(data_obj);

} *catch*(_com.sun.star_.uno.Exception ex) {

System.err.println(ex.getMessage());

} *finally*{

System.exit(1);

}

_}_

       }

*public**void*closeDocument(_XComponent_ document) {

_XModel_ model = _UnoRuntime_.queryInterface(_XModel_.*class*, document);

*if*(model != *null*) {

_XCloseable_ closeable = _UnoRuntime_.queryInterface(_XCloseable_.*class*, model);

*if*(closeable != *null*) {

*try*{

closeable.close(*false*);

} *catch*(_CloseVetoException_ ex) {

System./out/.println(ex.getMessage());

}

}

} *else*{

_XComponent_ disposeable = _UnoRuntime_.queryInterface(_XCompnent_.*class*, model);

disposeable.dispose();

}

       }

*public**void*ExportDocumentAs(_XComponent_ doc, String save_file, _DocumentHandler_.DocumentSaveFormat format, *boolean*overwrite, String page_range) {

*if*((save_file == *null*) || (save_file.trim().length()) == 0) {

*return*;

}

*if*(!overwrite) {

_File_ sfile = *new*_File_(save_file);

*if*(sfile.exists()) {

*throw**new*Exception("File exists");

}

}

_DocumentHandler_ = *new*_DocumentHandler_();

String file_url = _handler_.convertFIlePAthToUrl(save_file);

_XStoreable_ store = _UnoRuntime_.queryInterface(_XStoreable_.*class*, doc);

_PropertyValue_ filter_data= *new*_PropertyValue_[1];

_loadProps_[0] = *new*_PropertyValue_();

_loadProps_[0].Name = "PageRange";

_loadProps_[0].Value = page_range;

_PropertyValue_ loadProps= *new*_PropertyValue_[2];

loadProps[0] = *new*_PropertyValue_();

loadProps[0].Name = "FilterName";

loadProps[0].Value = format.getFormatCode;

loadProps[1] = *new*_PropertyValue_();

loadProps[1].Name = "FilterData";

loadProps[1].Value = filter_data;

store.storeToUrl(file_url, loadProps);

}

}

*From:*Andre Fischer [mailto:awf....@gmail.com]
*Sent:* Wednesday, February 26, 2014 3:15 AM
*To:* Steele, Raymond; Andre Fischer; api@openoffice.apache.org <mailto:api@openoffice.apache.org>
*Subject:* Re: EXTERNAL: Re: DisposedException

On 26.02.2014 00:25, Steele, Raymond wrote:

    Thanks,

    I am not explicitly calling the dispose method .


I would expect that dispose is called by a closing frame or something like that.



Here is an overview of what I am doing.

1.opening a XSpreadsheetDocument (called temp_doc) by calling after creating an object using XMultiComponentFactory::createInstanceWithContext.

a.The document is a .ots file which opens as "Untitled 1".

2.XComponent temp_comp = UnoRuntime.queryInterface(XComponent.class, temp_doc);

3.XStoreable store = UnoRuntime.queryInterface(XStoreable.class, temp_comp);

a. exporting "Unititled 1", to an "ODF Spreadsheet", "StarOffice XML (Calc)" format by setting the PropertyValue FilterName property. Once the properties are set, I use XStoreable::stopToURL to save "Untitled 1" to "RawData.ods"

4.Then I close the document:

a.XModel model = UnoRuntime.queryInterface(XModel.class, document);

b.If model not null then, XCloseable closeable = UnoRuntime.queryInterface(XCloseable.class, model);

i.closeable.close(); (This is always the case that happens)

c.If model null then, XComponent disposable = UnoRuntime.queryInterface(Xcomponent.class, model);

i.disposable.dispose(); (My code never gets into this condition)

5.I then immediately open the file I exported in step three above by creating a new XSpreadsheetDocument (called doc), using the same methods defined in step one above, but when I do a

a.document = UnoRuntime.queryInterface(XpreadsheetDocument.class, xCalcComponent);

I receive: com.sun.star.lang.DisposedExcpetion

at com.sun.star.lib.uno.environments.remote.JobQueue.removeJob(JobQueue.java: 210)


Is it possible that xCalcComponent still belongs to temp_doc? That would explain why it is disposed. Otherwise, xCalcComponent should not be disposed directly after loading. Even if the loading failed, it should not be created in the first place and be NULL (well, an empty Reference, that contains NULL). I would ask for any exceptions during the second loading, but unfortunately OpenOffice throws a lot of exceptions that don't notify any errors but are used for normal communication (don't ask)

-Andre



Hopefully, this provides some context. Basically, I am opening an .ots file, saving(exporting) it as an .ods file and closing it. Then I open the .ods file so that I can populate the cells with data, but right after loadComponentFromURL, I try to query the XComponent returned from loadComponentFromURL to get the XSpreadsheetDocument. That is when I get the DisposedException.

-----Original Message-----
From: Andre Fischer [mailto:awf....@gmail.com]
Sent: Tuesday, February 25, 2014 1:26 AM
To: Steele, Raymond; api@openoffice.apache.org <mailto:api@openoffice.apache.org>
Cc: awf....@gmail.com <mailto:awf....@gmail.com>
Subject: Re: EXTERNAL: Re: DisposedException

On 24.02.2014 20:56, Steele, Raymond wrote:

> Thanks for responding. How can I determine what called dispose()?

If you want to know who calls dispose() then you have to place a breakpoint in the dispose() method of xCalcComponent.

If you want to know when dispose() is called then register a com::sun::star::lang::XEventListener at the xCalcComponent object. When it is disposed, it will call disposing(...) at the listener.

I am just not sure if it calls disposing() when the object is already disposed when the listener is registered. Probably not.

>   This is working in version AOO 3.3. Has something changed?

Without knowing the context this can easily be a timing problem in a multi-threaded environment: in AOO 3.3 some operation took longer resulting in the dispose() call made a few milliseconds later (or anything to this effect.)

-Andre

>

> -----Original Message-----

> From: Andre Fischer [mailto:awf....@gmail.com]

> Sent: Monday, February 24, 2014 3:54 AM

> To: api@openoffice.apache.org <mailto:api@openoffice.apache.org>

> Subject: EXTERNAL: Re: DisposedException

>

> On 21.02.2014 19:20, Steele, Raymond wrote:

>> While running my application using AOO 4.0.1 on Solaris 11, a star.lang.DisposedException is thrown inconsistently (sometimes it works) when I use UnoRuntime.queryInterface.

>>

>> The line of code causing the issue:

>>

>> XSpreadsheetDocument  document =

>> UnoRuntime.queryInterface(XSpreadsheetDocument.class,

>> xCalcCompinent);

> The DisposedException means that the throwing object has been marked by its owner for destruction in the near future. Any access after that results in the DisposedException being thrown.

>

> That means, that the line above is executed after xCalcCompinent has received a dispose() call.

>

> -Andre

>

>> This works perfectly when I use AOO 3.3, but not since upgrading to 4.0.1.

>>

>> Any help would be appreciated.

>>

>> Thanks,

>> Raymond

>>

>>

>

> ---------------------------------------------------------------------

> To unsubscribe, e-mail: api-unsubscr...@openoffice.apache.org <mailto:api-unsubscr...@openoffice.apache.org>

> For additional commands, e-mail: api-h...@openoffice.apache.org <mailto:api-h...@openoffice.apache.org>

>


Reply via email to