Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
liuyibox opened this issue Oct 5, 2020 · 0 comments
Open

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

liuyibox opened this issue Oct 5, 2020 · 0 comments

Comments

@liuyibox
Copy link

liuyibox commented Oct 5, 2020

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.

willjrogers added a commit that referenced this issue Feb 25, 2021
Fixed error where File resource was not closed when loading properties
from file.

Also updated incorrect examples.

This update addresses part #1 of issue #13
 (#13)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant