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

when patch relationship with empty list, class BraveRepositoryFilter throw exception. #438

Open
jianglibo opened this issue Jun 26, 2017 · 1 comment

Comments

@jianglibo
Copy link

jianglibo commented Jun 26, 2017

version: 3.0.1

Look at this code snippet:

		if (ids != null) {
			Iterator<Object> iterator = ids.iterator();
			pathBuilder.append(iterator.next());
			while (iterator.hasNext()) {
				pathBuilder.append(",");
				pathBuilder.append(iterator.next());
			}
			pathBuilder.append("/");
		}

pathBuilder.append(iterator.next()); will cause java.util.NoSuchElementException.

	private String getComponentName(RepositoryRequestSpec request) {
		ResourceField relationshipField = request.getRelationshipField();
		StringBuilder pathBuilder = new StringBuilder();
		String method = request.getMethod().toString();
		pathBuilder.append(COMPONENT_NAME);
		pathBuilder.append(COMPONENT_NAME_SEPARATOR);
		pathBuilder.append(method);
		pathBuilder.append(COMPONENT_NAME_SEPARATOR);
		pathBuilder.append("/");
		
		if (relationshipField == null) {
			pathBuilder.append(request.getQueryAdapter().getResourceInformation().getResourceType());
		}
		else {
			pathBuilder.append(relationshipField.getParentResourceInformation().getResourceType());
		}
		pathBuilder.append("/");
		
		Iterable<Object> ids = request.getIds();
		if (ids != null) {
			Iterator<Object> iterator = ids.iterator();
			pathBuilder.append(iterator.next());
			while (iterator.hasNext()) {
				pathBuilder.append(",");
				pathBuilder.append(iterator.next());
			}
			pathBuilder.append("/");
		}
		if (relationshipField != null) {
			pathBuilder.append(relationshipField.getJsonName());
			pathBuilder.append("/");
		}
		return pathBuilder.toString();
	}
@chb0github
Copy link
Contributor

Agreed - this is not well implemented. The original author of the code has left the project and it's for reasons like this. You're are welcome to offer a PR.

@katharsis-project katharsis-project deleted a comment from remmeier Jun 27, 2017
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

2 participants