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

make sure to unlock xml resource #1266

Merged
merged 3 commits into from
Mar 1, 2017

Conversation

shabanovd
Copy link
Member

if url is xml resource then it get read-locked
(similar to #1264 )

@shabanovd shabanovd added the bug issue confirmed as bug label Feb 18, 2017
}

private void notValidXar(String path) throws XPathException {
throw new XPathException(this, EXPathErrorCode.EXPDY001, path + " is not a valid .xar", new StringValue(path));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd suggest to have two simple throw exceptions on line 160 and 164 ; with this you could probably change the text into "Resource not found" and "Resource is not binary" .... which helps in finding a root cause.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Copy link
Member

@dizzzz dizzzz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One small suggestion, PR is good.

DocumentImpl doc = context.getBroker().getXMLResource(uri, LockMode.READ_LOCK);
if (doc == null) {
throw new XPathException(this, EXPathErrorCode.EXPDY001,
path + " is no .xar resource",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"is no .xar resource" -> " does not exist"

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

disagree, because your message unclear that problem around .xar

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you insist, can you fix the language so that it reads "is not a .xar resource"?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

} else if (doc.getResourceType() != DocumentImpl.BINARY_FILE) {
doc.getUpdateLock().release(LockMode.READ_LOCK);
throw new XPathException(this, EXPathErrorCode.EXPDY001,
path + " is not a valid .xar, it's not a binary resource",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

" is not a valid .xar, it's not a binary resource" -> " is not a valid .xar EXPath Package"

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the test is actually only if it is a binary resource.....

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dizzzz Yes I realise that

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so, message must include information that it fail because resource is not binary

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The spec for EXPath packages says that they must be valid Zip files. Therefore a valid Xar can only be a binary file. As such I think that means the error can be simplified and improved here

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The xar file can be invalid for many reasons: corrupted zip, missing file at zip, wrong folders structure. This error define clearly that eXist do not see that resource as binary one.

@shabanovd
Copy link
Member Author

It's unclear for me how to write test for it. @adamretter, please do, if you know how to.

@dizzzz
Copy link
Member

dizzzz commented Feb 18, 2017

I have no idea either

@adamretter
Copy link
Member

adamretter commented Feb 18, 2017

@shabanovd @dizzzz A test just needs to call InstallFunction#eval and afterwards check whether the lock is still held or not. Mocks will help!

@dizzzz
Copy link
Member

dizzzz commented Feb 19, 2017

speaking for myself, I'd still have no idea :-( It looks like "InstallFunction" has quite some dependancies with other initialised classes, probably thats is why you write Mock?

@joewiz
Copy link
Member

joewiz commented Mar 1, 2017

@adamretter @wolfgangmm Any outstanding concerns here?

@adamretter
Copy link
Member

adamretter commented Mar 1, 2017

@joewiz Yes, it was awaiting time for me to add a test as @shabanovd didn't want to do it.

However, I looked into adding a test, and there is no suitable place in the code-base to put it. Extension XQuery Modules for eXist do not currently have any JUnit tests :-(. extensions/test/src/ would fit with the current scheme, but would require a bunch of Ant work.

As this would require changes to the build system, I think I will park the concern of adding a test until after the Maven'ization of eXist; Maven explicitly has a place for tests for every source code root.

Copy link
Member

@adamretter adamretter left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you could just fix the error message language please then I will get this merged.

@adamretter adamretter merged commit 36836a5 into eXist-db:develop Mar 1, 2017
@shabanovd shabanovd deleted the bugfix/make_sure_to_unlock_2 branch March 3, 2017 21:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug issue confirmed as bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants