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

Using URLDecoder instead of String.replaceAll #429

Closed
wants to merge 3 commits into from
Closed

Conversation

escowles
Copy link
Contributor

escowles referenced this pull request Jul 28, 2014
- IT demonstrating failure when creating an object with a space in its path and then trying to perform a SPARQL update on it

Resolves: https://www.pivotaltracker.com/story/show/72296804
} catch ( UnsupportedEncodingException ex ) {
LOGGER.warn("Required encoding (UTF-8) not supported, trying undecoded path",ex);
path = subjects.getPathFromSubject(subject);
} catch ( NullPointerException ex ) {
Copy link

Choose a reason for hiding this comment

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

Why is there a NPE catch clause? I do not believe "subjects" nor "subject" will ever be null at this point, and I am not seeing an NPE defined on the decode() method.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Without the NPE catch clause, four tests fail because getPathFromSubject() returns null:

JcrPropertyStatementListenerTest.testAddedProhibitedStatement:150 » NullPointer
JcrPropertyStatementListenerTest.testAddedStatement:166 » NullPointer
JcrPropertyStatementListenerTest.testAddRdfType:257 » NullPointer
JcrPropertyStatementListenerTest.testAddRdfTypeForNonMixin:301 » NullPointer

I'd assumed that there were circumstances where this could be null, but if they just need to be mocked in the tests, then we can do that instead of catching the NPE.

Copy link
Contributor

Choose a reason for hiding this comment

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

The question is also about the semantics of getPathFromSubject(). Is it defined for any possible subject in the Fedora-managed namespaces, or only for some subset thereof, the subset that is backed by actual persisted JCR nodes?

Copy link

Choose a reason for hiding this comment

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

@escowles, I think that instead of working around erroneous mocking, we should write the correct functional code and mock accordingly. The "testAddedStatement" works by changing line:158 to:
when(mockSubjects.getPathFromSubject(mockSubject)).thenReturn("/some/path");
when(mockSession.getNode("/some/path")).thenReturn(mockSubjectNode);

I assume a similar update will work for the other tests.

@ajs6f, as for the semantics of getPathFromSubject(), it appears to depend on the IdentifierTranslator implementation. HttpIdentifierTranslator requires a valid JCR input path.

Copy link
Contributor

Choose a reason for hiding this comment

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

Well, that's a very basic problem. OO design 101 says that the caller of getPathFromSubject() shouldn't need to care (shouldn't even be able to care) about the impl-- IOW the semantics should be defined in IdentifierTranslator. (That's the old GraphSubjects, which I just renamed.)

Maybe a topic for committer discussion?

@awoods
Copy link

awoods commented Jul 28, 2014

Resolved with: 3279475

Related to: https://www.pivotaltracker.com/story/show/72296804

@awoods awoods closed this Jul 28, 2014
@cbeer cbeer deleted the urldecode branch October 17, 2014 00:31
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

Successfully merging this pull request may close these issues.

None yet

3 participants