Skip to content

w/system: a resource failed to call end(close). #13

@liuyibox

Description

@liuyibox

Although this may not happen on desktop or laptop machine, directly using metamaplite in android produces w/system: a resource failed to call end(close). This error is basically caused by un-released fileinputstream or fileoutputstream. On android, the newly opened fileinputstream or fileoutputstream needs to be closed explicitly. In particular, this error comes from 2 sides when using metamaplite on android:

  1. from metamaplite:
    For example, in Example.java and Example2.java, the newly created FileReader is not closed after usage, so they need to be explicitly closed as shown below:
            FileReader fr = new FileReader("./config/metamaplite.properties");
            myProperties.load(fr);
            ...
            fr.close();
  1. from 3rd party library:
    For example, in org.apache.opennlp, opennlp/tools/util/model/BaseModel.java(loadModel) and opennlp/tools/util/model/BaseModel.java(finishLoadingArtifacts), ZipInputStream zip is not explicitly closed. This can be achieved by the following:
  • In loadModel method:
            final ZipInputStream zip = new ZipInputStream(in);
            ...
            zip.close()
  • In finishLoadingArtifacts
            ZipInputStream zip = new ZipInputStream((InputStream)in);
            ...
            zip.close()

If more attention is paied, here I replaced the final ZipInputStream zip = new ZipInputStream(in); with ZipInputStream zip = new ZipInputStream((InputStream)in);. Yes, only in this way I can re-compile the the opennlp source code into a jar file in maven. If there is an alternative, please let me know.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions