@@ -162,10 +162,8 @@ private List<RepositoryInfo> getRepositoriesInDir(final File projDir) {
162
162
}
163
163
164
164
private Project disableProject (String projectName ) {
165
- Project project = env .getProjects ().get (projectName );
166
- if (project == null ) {
167
- throw new IllegalStateException ("cannot get project \" " + projectName + "\" " );
168
- }
165
+ Project project = Optional .ofNullable (env .getProjects ().get (projectName )).
166
+ orElseThrow (() -> new NotFoundException ("cannot get project \" " + projectName + "\" " ));
169
167
170
168
// Remove the project from searches so no one can trip over incomplete index data.
171
169
project .setIndexed (false );
@@ -287,12 +285,9 @@ public Response deleteAnnotationCache(@Context HttpServletRequest request,
287
285
private Project getProjectFromName (String projectNameParam ) {
288
286
// Avoid classification as a taint bug.
289
287
final String projectName = Laundromat .launderInput (projectNameParam );
290
- Project project = env .getProjects ().get (projectName );
291
- if (project == null ) {
292
- throw new IllegalStateException ("cannot get project \" " + projectName + "\" " );
293
- }
294
288
295
- return project ;
289
+ return Optional .ofNullable (env .getProjects ().get (projectName )).
290
+ orElseThrow (() -> new NotFoundException ("cannot get project \" " + projectName + "\" " ));
296
291
}
297
292
298
293
@ DELETE
@@ -339,11 +334,8 @@ public Response markIndexed(@Context HttpServletRequest request, @PathParam("pro
339
334
// Avoid classification as a taint bug.
340
335
final String projectName = Laundromat .launderInput (projectNameParam );
341
336
342
- Project project = env .getProjects ().get (projectName );
343
- if (project == null ) {
344
- LOGGER .log (Level .WARNING , "cannot find project ''{0}'' to mark as indexed" , projectName );
345
- throw new NotFoundException (String .format ("project '%s' does not exist" , projectName ));
346
- }
337
+ Project project = Optional .ofNullable (env .getProjects ().get (projectName )).
338
+ orElseThrow (() -> new NotFoundException ("cannot get project \" " + projectName + "\" " ));
347
339
348
340
project .setIndexed (true );
349
341
@@ -411,16 +403,14 @@ public void set(
411
403
@ GET
412
404
@ Path ("/{project}/property/{field}" )
413
405
@ Produces (MediaType .APPLICATION_JSON )
414
- public Object get (@ PathParam ("project" ) String projectName , @ PathParam ("field" ) String field )
406
+ public Object get (@ PathParam ("project" ) String projectNameParam , @ PathParam ("field" ) String field )
415
407
throws IOException {
416
408
// Avoid classification as a taint bug.
417
- projectName = Laundromat .launderInput (projectName );
409
+ final String projectName = Laundromat .launderInput (projectNameParam );
418
410
field = Laundromat .launderInput (field );
419
411
420
- Project project = env .getProjects ().get (projectName );
421
- if (project == null ) {
422
- throw new NotFoundException (String .format ("cannot find project '%s' to get a property" , projectName ));
423
- }
412
+ Project project = Optional .ofNullable (env .getProjects ().get (projectName )).
413
+ orElseThrow (() -> new NotFoundException ("cannot get project \" " + projectName + "\" " ));
424
414
return ClassUtil .getFieldValue (project , field );
425
415
}
426
416
0 commit comments