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

Copiers optimizations #5252

Merged
merged 1 commit into from
Jun 24, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public Object copy(Object object) {

Method cloneMethod = getMethod(object, "clone");

if (!cloneMethod.isAccessible()) {
if (!cloneMethod.canAccess(object)) {
cloneMethod.setAccessible(true);
}

Expand Down
23 changes: 8 additions & 15 deletions impl/src/main/java/com/sun/faces/util/copier/CopierUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,14 @@ public class CopierUtils {
private static final String ERROR_COPIER_NAME = "The copier name should be a Java valid simple/qualified name.";
private static final String COPIER_PREFIX = "com.sun.faces.util.copier.";

private final static Set<String> keywords;

static {
Set<String> s = new HashSet<>();
String[] kws = { "abstract", "continue", "for", "new", "switch", "assert", "default", "if", "package", "synchronized", "boolean", "do", "goto",
"private", "this", "break", "double", "implements", "protected", "throw", "byte", "else", "import", "public", "throws", "case", "enum",
"instanceof", "return", "transient", "catch", "extends", "int", "short", "try", "char", "final", "interface", "static", "void", "class",
"finally", "long", "strictfp", "volatile", "const", "float", "native", "super", "while",
// literals
"null", "true", "false" };
for (String kw : kws) {
s.add(kw);
}
keywords = Collections.unmodifiableSet(s);
}
private final static Set<String> keywords = Set.of(
"abstract", "continue", "for", "new", "switch", "assert", "default", "if", "package", "synchronized", "boolean", "do", "goto",
"private", "this", "break", "double", "implements", "protected", "throw", "byte", "else", "import", "public", "throws", "case", "enum",
"instanceof", "return", "transient", "catch", "extends", "int", "short", "try", "char", "final", "interface", "static", "void", "class",
"finally", "long", "strictfp", "volatile", "const", "float", "native", "super", "while",
// literals
"null", "true", "false"
);

public static Copier getCopier(FacesContext context, String copierType) {
Copier copier = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public class CopyCtorCopier implements Copier {
public Object copy(Object object) {

try {
Constructor<? extends Object> copyConstructor = object.getClass().getConstructor(object.getClass());
Constructor<?> copyConstructor = object.getClass().getConstructor(object.getClass());

return copyConstructor.newInstance(object);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
*/
public class MultiStrategyCopier implements Copier {

private static final List<Copier> COPIERS = asList( // Note: copier instances used here must be thread-safe!
private static final List<Copier> COPIERS = List.of( // Note: copier instances used here must be thread-safe!
new SerializationCopier(), new CloneCopier(), new CopyCtorCopier(), new NewInstanceCopier());

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

package com.sun.faces.util.copier;

import java.lang.reflect.InvocationTargetException;

/**
* Copier that doesn't actually copy an object fully, but just returns a new instance of the same type.
* <p>
Expand All @@ -30,8 +32,8 @@ public class NewInstanceCopier implements Copier {
@Override
public Object copy(Object object) {
try {
return object.getClass().newInstance();
} catch (InstantiationException | IllegalAccessException e) {
return object.getClass().getDeclaredConstructor().newInstance();
} catch (InstantiationException | IllegalAccessException | NoSuchMethodException | InvocationTargetException e) {
throw new IllegalStateException(e);
}
}
Expand Down