Wrap URLEncoder, URLDecoder
These classes throw an exception that is ugly to work with when using UTF-8 encoding as the JVM is required to support UTF-8, which means the declared exception cannot occur. Wrap these into a helper class that catches the declared exception and rethrows as RuntimeException. Change-Id: Id277cf029348583f5edad5f5447b4ec4198dc980
This commit is contained in:
@@ -22,12 +22,10 @@ import com.google.gerrit.extensions.restapi.TopLevelResource;
|
||||
import com.google.gerrit.reviewdb.client.Project;
|
||||
import com.google.gerrit.server.CurrentUser;
|
||||
import com.google.gerrit.server.OutputFormat;
|
||||
import com.google.gerrit.server.util.Url;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Provider;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URLDecoder;
|
||||
|
||||
public class ProjectsCollection implements
|
||||
RestCollection<TopLevelResource, ProjectResource> {
|
||||
private final DynamicMap<RestView<ProjectResource>> views;
|
||||
@@ -56,7 +54,9 @@ public class ProjectsCollection implements
|
||||
throws ResourceNotFoundException {
|
||||
ProjectControl ctl;
|
||||
try {
|
||||
ctl = controlFactory.controlFor(decode(id), user.get());
|
||||
ctl = controlFactory.controlFor(
|
||||
new Project.NameKey(Url.decode(id)),
|
||||
user.get());
|
||||
} catch (NoSuchProjectException e) {
|
||||
throw new ResourceNotFoundException(id);
|
||||
}
|
||||
@@ -66,14 +66,6 @@ public class ProjectsCollection implements
|
||||
return new ProjectResource(ctl);
|
||||
}
|
||||
|
||||
private static Project.NameKey decode(String id) {
|
||||
try {
|
||||
return new Project.NameKey(URLDecoder.decode(id, "UTF-8"));
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
throw new RuntimeException("JVM does not support UTF-8", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public DynamicMap<RestView<ProjectResource>> views() {
|
||||
return views;
|
||||
|
||||
Reference in New Issue
Block a user