Skip to content

Commit 1e00604

Browse files
committed
pmd
1 parent 1632d2c commit 1e00604

File tree

2 files changed

+21
-19
lines changed

2 files changed

+21
-19
lines changed

datamodel/openapi/openapi-core/src/main/java/com/sap/cloud/sdk/services/openapi/apache/ApiClient.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ public static String parameterToString( @Nullable final Object param )
182182
return formatDate(date);
183183
} else if( param instanceof Collection ) {
184184
final StringBuilder b = new StringBuilder();
185-
for( Object o : (Collection<?>) param ) {
185+
for( final Object o : (Collection<?>) param ) {
186186
if( !b.isEmpty() ) {
187187
b.append(',');
188188
}
@@ -247,7 +247,7 @@ public static List<Pair> parameterToPairs(
247247

248248
// create the params based on the collection format
249249
if( "multi".equals(collectionFormat) ) {
250-
for( Object item : value ) {
250+
for( final Object item : value ) {
251251
params.add(new Pair(name, escapeString(parameterToString(item))));
252252
}
253253
return params;
@@ -263,7 +263,7 @@ public static List<Pair> parameterToPairs(
263263
};
264264

265265
final StringBuilder sb = new StringBuilder();
266-
for( Object item : value ) {
266+
for( final Object item : value ) {
267267
sb.append(delimiter);
268268
sb.append(escapeString(parameterToString(item)));
269269
}
@@ -288,7 +288,7 @@ public static String selectHeaderAccept( @Nonnull final String[] accepts )
288288
if( accepts.length == 0 ) {
289289
return null;
290290
}
291-
for( String accept : accepts ) {
291+
for( final String accept : accepts ) {
292292
if( isJsonMime(accept) ) {
293293
return accept;
294294
}
@@ -310,7 +310,7 @@ public static String selectHeaderContentType( @Nonnull final String[] contentTyp
310310
if( contentTypes.length == 0 || contentTypes[0].equals("*/*") ) {
311311
return "application/json";
312312
}
313-
for( String contentType : contentTypes ) {
313+
for( final String contentType : contentTypes ) {
314314
if( isJsonMime(contentType) ) {
315315
return contentType;
316316
}
@@ -342,7 +342,7 @@ private ContentType getContentType( @Nonnull final String headerValue )
342342
return ContentType.parse(headerValue);
343343
}
344344
catch( UnsupportedCharsetException e ) {
345-
throw new OpenApiRequestException("Could not parse content type " + headerValue);
345+
throw new OpenApiRequestException("Could not parse content type " + headerValue, e);
346346
}
347347
}
348348

@@ -378,7 +378,7 @@ private HttpEntity serialize(
378378
}
379379
} else if( mimeType.equals(ContentType.MULTIPART_FORM_DATA.getMimeType()) ) {
380380
final MultipartEntityBuilder multiPartBuilder = MultipartEntityBuilder.create();
381-
for( Entry<String, Object> paramEntry : formParams.entrySet() ) {
381+
for( final Entry<String, Object> paramEntry : formParams.entrySet() ) {
382382
final Object value = paramEntry.getValue();
383383
if( value instanceof File file ) {
384384
multiPartBuilder.addBinaryBody(paramEntry.getKey(), file);
@@ -432,13 +432,13 @@ private HttpEntity serialize(
432432
*/
433433
@Nonnull
434434
private String buildUrl(
435-
@Nullable final String path,
435+
@Nonnull final String path,
436436
@Nullable final List<Pair> queryParams,
437437
@Nullable final List<Pair> collectionQueryParams,
438438
@Nullable final String urlQueryDeepObject )
439439
{
440440
final StringBuilder url = new StringBuilder();
441-
if( basePath.endsWith("/") && path != null && path.startsWith("/") ) {
441+
if( basePath.endsWith("/") && path.startsWith("/") ) {
442442
url.append(basePath, 0, basePath.length() - 1);
443443
} else {
444444
url.append(basePath);
@@ -448,7 +448,7 @@ private String buildUrl(
448448
if( queryParams != null && !queryParams.isEmpty() ) {
449449
// support (constant) query string in `path`, e.g. "/posts?draft=1"
450450
String prefix = path.contains("?") ? "&" : "?";
451-
for( Pair param : queryParams ) {
451+
for( final Pair param : queryParams ) {
452452
if( prefix != null ) {
453453
url.append(prefix);
454454
prefix = null;
@@ -463,7 +463,7 @@ private String buildUrl(
463463

464464
if( collectionQueryParams != null && !collectionQueryParams.isEmpty() ) {
465465
String prefix = url.toString().contains("?") ? "&" : "?";
466-
for( Pair param : collectionQueryParams ) {
466+
for( final Pair param : collectionQueryParams ) {
467467
if( prefix != null ) {
468468
url.append(prefix);
469469
prefix = null;
@@ -548,7 +548,7 @@ public <T> T invokeAPI(
548548
if( accept != null ) {
549549
builder.addHeader("Accept", accept);
550550
}
551-
for( Entry<String, String> keyValue : headerParams.entrySet() ) {
551+
for( final Entry<String, String> keyValue : headerParams.entrySet() ) {
552552
builder.addHeader(keyValue.getKey(), keyValue.getValue());
553553
}
554554

datamodel/openapi/openapi-core/src/main/java/com/sap/cloud/sdk/services/openapi/apache/DefaultApiResponseHandler.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -227,8 +227,9 @@ private File prepareDownloadFile( @Nullable final String contentDisposition )
227227
// Get filename from the Content-Disposition header.
228228
final Pattern pattern = Pattern.compile("filename=['\"]?([^'\"\\s]+)['\"]?");
229229
final Matcher matcher = pattern.matcher(contentDisposition);
230-
if( matcher.find() )
230+
if( matcher.find() ) {
231231
filename = matcher.group(1);
232+
}
232233
}
233234

234235
String prefix;
@@ -245,14 +246,15 @@ private File prepareDownloadFile( @Nullable final String contentDisposition )
245246
suffix = filename.substring(pos);
246247
}
247248
// Files.createTempFile requires the prefix to be at least three characters long
248-
if( prefix.length() < 3 )
249+
if( prefix.length() < 3 ) {
249250
prefix = "download-";
251+
}
250252
}
251253

252-
if( tempFolderPath == null )
254+
if( tempFolderPath == null ) {
253255
return Files.createTempFile(prefix, suffix).toFile();
254-
else
255-
return Files.createTempFile(Paths.get(tempFolderPath), prefix, suffix).toFile();
256+
}
257+
return Files.createTempFile(Paths.get(tempFolderPath), prefix, suffix).toFile();
256258
}
257259

258260
/**
@@ -292,7 +294,7 @@ private static ContentType parseContentType( @Nonnull final String headerValue )
292294
return ContentType.parse(headerValue);
293295
}
294296
catch( UnsupportedCharsetException e ) {
295-
throw new OpenApiRequestException("Could not parse content type " + headerValue);
297+
throw new OpenApiRequestException("Could not parse content type " + headerValue, e);
296298
}
297299
}
298300

@@ -307,7 +309,7 @@ private static ContentType parseContentType( @Nonnull final String headerValue )
307309
private static Map<String, List<String>> transformResponseHeaders( @Nonnull final Header[] headers )
308310
{
309311
final Map<String, List<String>> headersMap = new HashMap<>();
310-
for( Header header : headers ) {
312+
for( final Header header : headers ) {
311313
List<String> valuesList = headersMap.get(header.getName());
312314
if( valuesList != null ) {
313315
valuesList.add(header.getValue());

0 commit comments

Comments
 (0)