Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ Changes log
- Bugs fixed
- Slf4j bridge reports wrong line number and caller class in log4j. Issue #233.
- When GET is an allowed method of a server resource, HEAD is now also listed (e.g. in the Allow header of a 405 response). Issue #266.
- Misc
- Pinned the Maven Deploy plugin to version 3.2.0 (avoids resolving incompatible Maven 4 beta versions).

- 3.0 Milestone 1 (10-11-2026)
- Breaking changes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,8 @@ public <T> T toObject(Representation source, Class<T> target, Resource resource)
// The source for the gson conversion
GsonRepresentation<?> gsonSource = null;

if (source instanceof GsonRepresentation) {
gsonSource = (GsonRepresentation<?>) source;
if (source instanceof GsonRepresentation<?> representation) {
gsonSource = representation;
} else if (VARIANT_JSON.isCompatible(source)) {
gsonSource = create(source, target);
}
Expand All @@ -143,8 +143,8 @@ public <T> T toObject(Representation source, Class<T> target, Resource resource)
public Representation toRepresentation(Object source, Variant target, Resource resource) {
Representation result = null;

if (source instanceof GsonRepresentation) {
result = (GsonRepresentation<?>) source;
if (source instanceof GsonRepresentation<?> representation) {
result = representation;
} else {
if (target.getMediaType() == null) {
target.setMediaType(MediaType.APPLICATION_JSON);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,8 @@ public <T> T toObject(Representation source, Class<T> target, Resource resource)

// The source for the Jackson conversion
JacksonRepresentation<?> jacksonSource = null;
if (source instanceof JacksonRepresentation) {
jacksonSource = (JacksonRepresentation<?>) source;
if (source instanceof JacksonRepresentation<?> representation) {
jacksonSource = representation;
} else if (isCompatible(source)) {
jacksonSource = create(source, target);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@
package org.restlet.ext.jackson;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import java.io.Serial;

@JsonIgnoreProperties({"cause", "localizedMessage", "suppressed", "message"})
public class MyException extends Exception {

private static final long serialVersionUID = 1L;
@Serial private static final long serialVersionUID = 1L;

@SuppressWarnings("serial")
private Customer customer;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,17 +157,12 @@ public <T> T toObject(Representation source, Class<T> target, Resource resource)

@Override
public Representation toRepresentation(Object source, Variant target, Resource resource) {
Representation result = null;

if (source instanceof JSONArray jsonArray) {
result = new JsonRepresentation(jsonArray);
} else if (source instanceof JSONObject jsonObject) {
result = new JsonRepresentation(jsonObject);
} else if (source instanceof JSONTokener jsonTokener) {
result = new JsonRepresentation(jsonTokener);
}

return result;
return switch (source) {
case JSONArray jsonArray -> new JsonRepresentation(jsonArray);
case JSONObject jsonObject -> new JsonRepresentation(jsonObject);
case JSONTokener jsonTokener -> new JsonRepresentation(jsonTokener);
case null, default -> null;
};
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,27 +191,17 @@ private String getJsonText() throws JSONException {
}

private String getJsonTextFromJsonValue() {
final String result;
switch (this.jsonValue) {
case final JSONArray jsonArray -> {
if (isIndenting()) {
result = jsonArray.toString(getIndentingSize());
} else {
result = jsonArray.toString();
}
}
case final JSONObject jsonObject -> {
if (isIndenting()) {
result = jsonObject.toString(getIndentingSize());
} else {
result = jsonObject.toString();
}
}
case final JSONStringer jsonStringer -> result = jsonStringer.toString();
case final JSONTokener jsonTokener -> result = jsonTokener.toString();
case null, default -> result = null;
}
return result;
return switch (this.jsonValue) {
case final JSONArray jsonArray when isIndenting() ->
jsonArray.toString(getIndentingSize());
case final JSONArray jsonArray -> jsonArray.toString();
case final JSONObject jsonObject when isIndenting() ->
jsonObject.toString(getIndentingSize());
case final JSONObject jsonObject -> jsonObject.toString();
case final JSONStringer jsonStringer -> jsonStringer.toString();
case final JSONTokener jsonTokener -> jsonTokener.toString();
case null, default -> null;
};
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@
*/
package org.restlet.ext.openapi.internal;

import java.io.Serial;
import org.restlet.resource.Status;

@Status(500)
public class OpenApiApplicationException extends RuntimeException {

private static final long serialVersionUID = 1L;
@Serial private static final long serialVersionUID = 1L;

public OpenApiApplicationException(final String message, final Throwable cause) {
super(message, cause);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ void testLocationAwareLoggerReceivesCallerBoundary() {
for (Object[] call : calls) {
assertEquals(Slf4jLogger.class.getName(), call[1]);
}
assertEquals(LocationAwareLogger.INFO_INT, calls.get(0)[2]);
assertEquals(LocationAwareLogger.INFO_INT, calls.getFirst()[2]);
assertEquals(LocationAwareLogger.WARN_INT, calls.get(1)[2]);
assertEquals(LocationAwareLogger.ERROR_INT, calls.get(2)[2]);
assertEquals(t, calls.get(2)[5]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,8 @@ private Set<String> routeUris(RouteList routes) {
Set<String> uris = new HashSet<>();

for (Route actualRoute : routes) {
if (actualRoute instanceof TemplateRoute) {
uris.add(((TemplateRoute) actualRoute).getTemplate().getPattern());
if (actualRoute instanceof TemplateRoute route) {
uris.add(route.getTemplate().getPattern());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
*/
package org.restlet.engine.application;

import java.io.Serial;
import java.io.Serializable;
import org.restlet.data.Status;

Expand All @@ -18,7 +19,7 @@
*/
public class StatusInfo implements Serializable {

private static final long serialVersionUID = 1L;
@Serial private static final long serialVersionUID = 1L;

/** The specification code. */
private volatile int code;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import java.io.RandomAccessFile;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
Expand Down Expand Up @@ -237,7 +236,7 @@ private static boolean isFileInDirectory(final Directory directory, final File f
filePath = fileAbsolute;
}

final Path rootDirectoryPath = Paths.get(filePath).normalize();
final Path rootDirectoryPath = Path.of(filePath).normalize();
final Path actualFilePath = file.toPath().normalize();
result = !rootDirectoryPath.relativize(actualFilePath).toString().startsWith("..");
}
Expand Down Expand Up @@ -640,23 +639,9 @@ public boolean isResumeUpload() {
* @param metadata The metadata.
*/
private void updateFileExtension(StringBuilder fileName, Metadata metadata) {
boolean defaultMetadata = true;

if (getMetadataService() != null) {
if (metadata instanceof Language language) {
defaultMetadata = language.equals(getMetadataService().getDefaultLanguage());
} else if (metadata instanceof MediaType mediaType) {
defaultMetadata = mediaType.equals(getMetadataService().getDefaultMediaType());
} else if (metadata instanceof CharacterSet characterSet) {
defaultMetadata =
characterSet.equals(getMetadataService().getDefaultCharacterSet());
} else if (metadata instanceof Encoding encoding) {
defaultMetadata = encoding.equals(getMetadataService().getDefaultEncoding());
}
}

// We only add an extension for metadata that differs from default ones
if (!defaultMetadata) {
if (!isDefaultMetadata(metadata)) {
String extension = getMetadataService().getExtension(metadata);

if (extension != null) {
Expand All @@ -668,4 +653,19 @@ private void updateFileExtension(StringBuilder fileName, Metadata metadata) {
}
}
}

private boolean isDefaultMetadata(Metadata metadata) {
if (getMetadataService() == null) {
return true;
}
return switch (metadata) {
case Language language -> language.equals(getMetadataService().getDefaultLanguage());
case MediaType mediaType ->
mediaType.equals(getMetadataService().getDefaultMediaType());
case CharacterSet characterSet ->
characterSet.equals(getMetadataService().getDefaultCharacterSet());
case Encoding encoding -> encoding.equals(getMetadataService().getDefaultEncoding());
case null, default -> true;
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import java.nio.file.FileStore;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.attribute.FileAttribute;
import java.nio.file.attribute.PosixFilePermission;
import java.nio.file.attribute.PosixFilePermissions;
Expand Down Expand Up @@ -167,10 +166,10 @@ private static Path getPrivateTempHomeRoot() {
String userHome = System.getProperty("user.home");

if (userHome != null && !userHome.isEmpty()) {
return Paths.get(userHome);
return Path.of(userHome);
}

return Paths.get(".").toAbsolutePath().normalize();
return Path.of(".").toAbsolutePath().normalize();
}

private static void setOwnerOnlyAccess(File file, boolean executable) throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public abstract class AnnotationInfo {
* @return The actual type.
*/
protected static Class<?> getJavaActualType(Class<?> currentClass, String genericTypeName) {
Class<?> result = null;
Class<?> result;

// Lookup in the super class
result = getJavaActualType(currentClass.getGenericSuperclass(), genericTypeName);
Expand Down Expand Up @@ -61,9 +61,9 @@ protected static Class<?> getJavaActualType(Type currentType, String genericType
Class<?> result = null;

if (currentType != null) {
if (currentType instanceof Class<?>) {
if (currentType instanceof Class<?> class1) {
// Look in the generic super class or the implemented interfaces
result = getJavaActualType((Class<?>) currentType, genericTypeName);
result = getJavaActualType(class1, genericTypeName);
} else if (currentType instanceof final ParameterizedType parameterizedType) {
Class<?> rawType = (Class<?>) parameterizedType.getRawType();
Type[] actualTypeArguments = parameterizedType.getActualTypeArguments();
Expand All @@ -87,22 +87,20 @@ protected static Class<?> getJavaActualType(Type currentType, String genericType
* @return The underlying class
*/
protected static Class<?> getTypeClass(Type type) {
Class<?> result = null;
return switch (type) {
case Class<?> clazz -> clazz;
case ParameterizedType parameterizedType ->
getTypeClass(parameterizedType.getRawType());
case GenericArrayType genericArrayType -> getArrayTypeClass(genericArrayType);
case null, default -> null;
};
}

if (type instanceof Class<?>) {
result = (Class<?>) type;
} else if (type instanceof ParameterizedType parameterizedType) {
result = getTypeClass(parameterizedType.getRawType());
} else if (type instanceof GenericArrayType genericArrayType) {
Type componentType = genericArrayType.getGenericComponentType();
Class<?> componentClass = getTypeClass(componentType);
private static Class<?> getArrayTypeClass(GenericArrayType genericArrayType) {
Type componentType = genericArrayType.getGenericComponentType();
Class<?> componentClass = getTypeClass(componentType);

if (componentClass != null) {
result = Array.newInstance(componentClass, 0).getClass();
}
}

return result;
return (componentClass == null) ? null : Array.newInstance(componentClass, 0).getClass();
}

/** The raw annotation value. */
Expand Down Expand Up @@ -130,7 +128,7 @@ protected AnnotationInfo(
this.javaClass = javaClass;
this.javaMethod = javaMethod;
this.annotationValue = annotationValue;
java.lang.reflect.Method m = null;
java.lang.reflect.Method m;

try {
m = javaClass.getMethod(javaMethod.getName(), javaMethod.getParameterTypes());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,8 @@ private Class<?> resolveActualType(java.lang.reflect.Method javaMethod, int argI
Type genericParameterType = javaMethod.getGenericParameterTypes()[argIndex];
if (genericParameterType instanceof ParameterizedType parameterizedType) {
Type firstArg = parameterizedType.getActualTypeArguments()[0];
if (firstArg instanceof Class<?>) {
return (Class<?>) firstArg;
if (firstArg instanceof Class<?> clazz) {
return clazz;
}
}
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
*/
package org.restlet.engine.util;

import java.io.Serial;

/**
* Optimized public-domain implementation of a Java alphanumeric sort.
*
Expand All @@ -29,7 +31,7 @@
* @author Rob Heittman, <a href="http://www.solertium.com">Solertium Corporation</a>
*/
public class AlphaNumericComparator extends AlphabeticalComparator {
private static final long serialVersionUID = 1L;
@Serial private static final long serialVersionUID = 1L;

@Override
public int compare(final String uri0, final String uri1) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
*/
package org.restlet.engine.util;

import java.io.Serial;
import java.io.Serializable;
import java.util.Comparator;
import org.restlet.data.Reference;
Expand All @@ -18,7 +19,7 @@
* @author Jerome Louvel
*/
public class AlphabeticalComparator implements Comparator<Reference>, Serializable {
private static final long serialVersionUID = 1L;
@Serial private static final long serialVersionUID = 1L;

/**
* Compares two references.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@
*/
package org.restlet.engine.util;

import java.io.Serial;
import java.util.Collection;
import java.util.HashSet;

/** Implementation of the Set Interface that is case-insensitive. */
public class CaseInsensitiveHashSet extends HashSet<String> {

private static final long serialVersionUID = 1L;
@Serial private static final long serialVersionUID = 1L;

/**
* Constructor initializing the set with the given collection.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
*/
package org.restlet.engine.util;

import java.io.Serial;
import java.util.Date;

/**
Expand All @@ -20,7 +21,7 @@
*/
public final class ImmutableDate extends Date {

private static final long serialVersionUID = -5946186780670229206L;
@Serial private static final long serialVersionUID = -5946186780670229206L;

/**
* Private constructor. A factory method is provided.
Expand Down
Loading
Loading