rjdverse / rjdemetra

R interface to JDemetra+ v 2.x
https://rjdverse.github.io/rjdemetra
52 stars 16 forks source link

Loading of a workspace fails with an error #53

Closed djhurio closed 5 years ago

djhurio commented 5 years ago

I am trying to load an existing workspace which was created with JDemetra+. The loading fails with the following error. Do you have any idea what could be a reason?

The workspace contains user-defined calendar regressors. Could it be a problem?

> ws <- load_workspace(file = "data2/areja_tirdz.xml")
Error in .jcall("ec/tstoolkit/jdr/ws/Workspace", "Lec/tstoolkit/jdr/ws/Workspace;",  : 
  java.io.IOException: Unexpected exception while loading SAProcessing-1
AQLT commented 5 years ago

No I don't think it comes from the user-defined calendar reggressors if you use the last version of RJDemetra. What are the names of your multi-documents? Does the first one contain special characters like [ , ] , ;?

djhurio commented 5 years ago

See the names in the attached image. I am quite sure the error is not related with the names of time series. I can create a new workspace with the same data provider. Then I will be able to import the newly created workshpace into RJDemetra.

image

AQLT commented 5 years ago

I think it comes from the name of your first multi-document: could you try removing the [ ]?

djhurio commented 5 years ago

I have removed the [ ] now. But it does not help. I am still unable to import the workspace.

        <ns2:item readOnly="false">
            <ns2:family>Seasonal adjustment@multi-documents</ns2:family>
            <ns2:name>Areja_tirdz_old2018</ns2:name>
            <ns2:file>SAProcessing-1</ns2:file>
        </ns2:item>
charphi commented 5 years ago

Could you paste here the full stack trace of the error?

djhurio commented 5 years ago

Is this what are you asking for?

> load_workspace(file = "data2/areja_tirdz.xml")
Error in .jcall("ec/tstoolkit/jdr/ws/Workspace", "Lec/tstoolkit/jdr/ws/Workspace;",  : 
  java.io.IOException: Unexpected exception while loading SAProcessing-1
> traceback()
4: stop(list(message = "java.io.IOException: Unexpected exception while loading SAProcessing-1", 
       call = .jcall("ec/tstoolkit/jdr/ws/Workspace", "Lec/tstoolkit/jdr/ws/Workspace;", 
           "open", file), jobj = new("jobjRef", jobj = <pointer: 0x0000017cbc4e2ff0>, 
           jclass = "java/io/IOException")))
3: .jcheck(silent = FALSE)
2: .jcall("ec/tstoolkit/jdr/ws/Workspace", "Lec/tstoolkit/jdr/ws/Workspace;", 
       "open", file)
1: load_workspace(file = "data2/areja_tirdz.xml")
charphi commented 5 years ago

Not exactly. The stack trace represents the details of the error and might give us the source of the problem.

Could you try the following solution: https://stackoverflow.com/questions/34132229/rjava-how-to-get-stack-traces-more-verbose-error

djhurio commented 5 years ago

Thanks for explanation! I hope this is the code I should be running.

.jcall(obj = "ec/tstoolkit/jdr/ws/Workspace",
       returnSig = "Lec/tstoolkit/jdr/ws/Workspace;",
       method = "open", 
       "data2/areja_tirdz.xml",
       check = FALSE)
ex <- .jgetEx()
.jcheck()
ex$printStackTrace()

The output:

> .jcall(obj = "ec/tstoolkit/jdr/ws/Workspace",
+        returnSig = "Lec/tstoolkit/jdr/ws/Workspace;",
+        method = "open", 
+        "data2/areja_tirdz.xml",
+        check = FALSE)
NULL
> ex <- .jgetEx()
> .jcheck()
Error: java.io.IOException: Unexpected exception while loading SAProcessing-1
> ex$printStackTrace()
java.io.IOException: Unexpected exception while loading SAProcessing-1
    at demetra.workspace.file.SafeHandler.loadValue(SafeHandler.java:58)
    at demetra.workspace.file.FileWorkspaceImpl.load(FileWorkspaceImpl.java:133)
    at demetra.workspace.file.FileRepository.loadAllSaProcessing(FileRepository.java:52)
    at ec.tstoolkit.jdr.ws.Workspace.open(Workspace.java:58)
Caused by: java.lang.NullPointerException: name is marked @NonNull but is null
    at demetra.datatypes.sa.SaItemType$Builder.name(SaItemType.java:37)
    at demetra.datatypes.sa.SaItemType.read(SaItemType.java:149)
    at demetra.datatypes.sa.SaProcessingType.read(SaProcessingType.java:95)
    at demetra.workspace.file.InformationSetSupport.xmlToItem(InformationSetSupport.java:92)
    at demetra.workspace.file.InformationSetSupport.readItem(InformationSetSupport.java:79)
    at demetra.workspace.file.InformationSetSupport.read(InformationSetSupport.java:63)
    at demetra.workspace.file.QuickHandler.read(QuickHandler.java:32)
    at demetra.workspace.file.GenericHandlers$SaMulti.read(GenericHandlers.java:64)
    at demetra.workspace.file.SafeHandler.loadValue(SafeHandler.java:56)
    ... 3 more
charphi commented 5 years ago

There is a bug in the code that throws an exception when a SaItem has at least one metadata and no name : https://github.com/nbbrd/jdemetra-sa-advanced/blob/499b93c169442a8afbc1ed114fc0f52fb9c40cba/jdr/src/main/java/demetra/datatypes/sa/SaItemType.java#L149

Two possible workarounds:

  1. add a custom name to the SaItem
  2. remove all metadata on SaItem (such as comments)
djhurio commented 5 years ago

Thanks a lot! Removing comments helps to load workspace into RJDemetra.

Could you please clarify the 1st workaround. Where the name should be added? The xml code for comments is:

            <item name="metadata">
                <subset>
                    <item name="comment">
                        <string>koriģē netieši</string>
                    </item>
                </subset>
            </item>

It looks we need to parse the SAProcessing xml files (for example, by deleting comments) before loading a workspace into RJDemetra.

charphi commented 5 years ago

The name node is located at the same level as metadata. For example:

<item name="name">
  <string>stuff</string>
</item>
<item name="metadata">
  <subset>
    <item name="comment">
      <string>koriģē netieši</string>
    </item>
  </subset>
</item>

You can also put a custom name directly in JD+ interface by right-clicking on an SaItem.

djhurio commented 5 years ago

Thanks @charphi! I confirm, the workaround with adding a custom name to a sa item works as well. However a name should be meaningful as it is used in JD+ GUI. I am adding a name to a sa item like this:

    <item name="sa1">
        <subset>
            <item name="name">
                <string>Eksports_pavisam</string>
            </item>
            <item name="ts">
                <ts name="Originalie&#xA;Eksports_pavisam">
                    <freq>12</freq>
                    <firstYear>2005</firstYear>
                    <firstPeriod>1</firstPeriod>

@charphi, could you please confirm the bug is in JD+ Java code? If so, do you have plans to make a correction for it? Do we have an issue for this bug open?

@AQLT, should we create some temporal workaround regarding this bug for RJDemetra? We are using comments quite a lot. So we are not able to load the current workspaces in RJDemetra right now. And we would not like to delete comments. Could it be a task for the RJDemetra Hackathon?

djhurio commented 5 years ago

@AQLT, do you know when the BugFix could be implemented into RJDemetra?

AQLT commented 5 years ago

The .jar is in my fork (https://github.com/AQLT/rjdemetra), I will do a PR/new release when I will have finished to add the parameters to set the calendarSigma to x13_spec. Meanwhile you can ever 1) use the development version send in Slack (#hackathonffm) July 1st, or 2) use the development version of my fork.