Skip to content

Add final & sealed to jdk.internal.reflect #24900

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

Closed
wants to merge 2 commits into from
Closed
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
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -31,7 +31,7 @@
/**
* Utility methods used by DirectMethodHandleAccessor and DirectConstructorHandleAccessor
*/
public class AccessorUtils {
public final class AccessorUtils {
/**
* Determines if the given exception thrown by MethodHandle::invokeExact
* is caused by an illegal argument passed to Method::invoke or
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2003, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -32,7 +32,7 @@
Currently this is needed to provide reflective access to annotations
but may be used by other internal subsystems in the future. */

public class ConstantPool {
public final class ConstantPool {
// Number of entries in this constant pool (= maximum valid constant pool index)
public int getSize() { return getSize0 (constantPoolOop); }
public Class<?> getClassAt (int index) { return getClassAt0 (constantPoolOop, index); }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2001, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2001, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -32,7 +32,7 @@
configured with a (possibly dynamically-generated) class which
implements this interface. */

public interface ConstructorAccessor {
public sealed interface ConstructorAccessor permits ConstructorAccessorImpl {
/** Matches specification in {@link java.lang.reflect.Constructor} */
public Object newInstance(Object[] args)
throws InstantiationException,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2001, 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2001, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -27,7 +27,8 @@

import java.lang.reflect.InvocationTargetException;

abstract class ConstructorAccessorImpl implements ConstructorAccessor {
abstract sealed class ConstructorAccessorImpl implements ConstructorAccessor
permits DirectConstructorHandleAccessor, DirectConstructorHandleAccessor.NativeAccessor, InstantiationExceptionConstructorAccessorImpl {
/** Matches specification in {@link java.lang.reflect.Constructor} */
public abstract Object newInstance(Object[] args)
throws InstantiationException,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -41,7 +41,7 @@
* the adapter method with the caller class parameter will be called
* instead.
*/
class CsMethodAccessorAdapter extends MethodAccessorImpl {
final class CsMethodAccessorAdapter extends MethodAccessorImpl {
private final Method csmAdapter;
private final MethodAccessor accessor;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -35,7 +35,7 @@

import static jdk.internal.reflect.MethodHandleAccessorFactory.SPECIALIZED_PARAM_COUNT;

class DirectConstructorHandleAccessor extends ConstructorAccessorImpl {
final class DirectConstructorHandleAccessor extends ConstructorAccessorImpl {
static ConstructorAccessorImpl constructorAccessor(Constructor<?> ctor, MethodHandle target) {
return new DirectConstructorHandleAccessor(ctor, target);
}
Expand Down Expand Up @@ -94,7 +94,7 @@ Object invokeImpl(Object[] args) throws Throwable {
/**
* Invoke the constructor via native VM reflection
*/
static class NativeAccessor extends ConstructorAccessorImpl {
static final class NativeAccessor extends ConstructorAccessorImpl {
private final Constructor<?> ctor;
NativeAccessor(Constructor<?> ctor) {
this.ctor = ctor;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021, 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -42,7 +42,7 @@
import static java.lang.invoke.MethodType.genericMethodType;
import static jdk.internal.reflect.MethodHandleAccessorFactory.LazyStaticHolder.JLIA;

class DirectMethodHandleAccessor extends MethodAccessorImpl {
final class DirectMethodHandleAccessor extends MethodAccessorImpl {
/**
* Creates a MethodAccessorImpl for a non-native method.
*/
Expand Down Expand Up @@ -203,7 +203,7 @@ private void checkReceiver(Object o) {
/**
* Invoke the method via native VM reflection
*/
static class NativeAccessor extends MethodAccessorImpl {
static final class NativeAccessor extends MethodAccessorImpl {
private final Method method;
private final Method csmAdapter;
private final boolean callerSensitive;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2001, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2001, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -30,7 +30,7 @@
(possibly dynamically-generated) class which implements this
interface. */

public interface FieldAccessor {
public sealed interface FieldAccessor permits FieldAccessorImpl {
/** Matches specification in {@link java.lang.reflect.Field} */
public Object get(Object obj) throws IllegalArgumentException;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2001, 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2001, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -28,7 +28,7 @@
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;

abstract class FieldAccessorImpl implements FieldAccessor {
abstract sealed class FieldAccessorImpl implements FieldAccessor permits MethodHandleFieldAccessorImpl {
protected final Field field;

FieldAccessorImpl(Field field) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2001, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2001, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -31,7 +31,7 @@
/** Throws an InstantiationException with given error message upon
newInstance() call */

class InstantiationExceptionConstructorAccessorImpl
final class InstantiationExceptionConstructorAccessorImpl
extends ConstructorAccessorImpl {
private final String message;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2001, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2001, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -33,7 +33,7 @@ configured with a (possibly dynamically-generated) class which
implements this interface.
*/

public interface MethodAccessor {
public sealed interface MethodAccessor permits MethodAccessorImpl {
/** Matches specification in {@link java.lang.reflect.Method} */
public Object invoke(Object obj, Object[] args)
throws IllegalArgumentException, InvocationTargetException;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2001, 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2001, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -36,7 +36,8 @@
methods for java.lang.reflect.Method.invoke(). </P>
*/

abstract class MethodAccessorImpl implements MethodAccessor {
abstract sealed class MethodAccessorImpl implements MethodAccessor
permits DirectMethodHandleAccessor, DirectMethodHandleAccessor.NativeAccessor, CsMethodAccessorAdapter {
/** Matches specification in {@link java.lang.reflect.Method} */
public abstract Object invoke(Object obj, Object[] args)
throws IllegalArgumentException, InvocationTargetException;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021, 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -438,7 +438,7 @@ public static boolean isSignaturePolymorphicMethod(Method method) {
/*
* Delay initializing these static fields until java.lang.invoke is fully initialized.
*/
static class LazyStaticHolder {
static final class LazyStaticHolder {
static final JavaLangInvokeAccess JLIA = SharedSecrets.getJavaLangInvokeAccess();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -30,7 +30,7 @@
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;

class MethodHandleBooleanFieldAccessorImpl extends MethodHandleFieldAccessorImpl {
final class MethodHandleBooleanFieldAccessorImpl extends MethodHandleFieldAccessorImpl {
static FieldAccessorImpl fieldAccessor(Field field, MethodHandle getter, MethodHandle setter, boolean isReadOnly) {
boolean isStatic = Modifier.isStatic(field.getModifiers());
if (isStatic) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -30,7 +30,7 @@
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;

class MethodHandleByteFieldAccessorImpl extends MethodHandleFieldAccessorImpl {
final class MethodHandleByteFieldAccessorImpl extends MethodHandleFieldAccessorImpl {
static FieldAccessorImpl fieldAccessor(Field field, MethodHandle getter, MethodHandle setter, boolean isReadOnly) {
boolean isStatic = Modifier.isStatic(field.getModifiers());
if (isStatic) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -30,7 +30,7 @@
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;

class MethodHandleCharacterFieldAccessorImpl extends MethodHandleFieldAccessorImpl {
final class MethodHandleCharacterFieldAccessorImpl extends MethodHandleFieldAccessorImpl {
static FieldAccessorImpl fieldAccessor(Field field, MethodHandle getter, MethodHandle setter, boolean isReadOnly) {
boolean isStatic = Modifier.isStatic(field.getModifiers());
if (isStatic) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -30,7 +30,7 @@
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;

class MethodHandleDoubleFieldAccessorImpl extends MethodHandleFieldAccessorImpl {
final class MethodHandleDoubleFieldAccessorImpl extends MethodHandleFieldAccessorImpl {
static FieldAccessorImpl fieldAccessor(Field field, MethodHandle getter, MethodHandle setter, boolean isReadOnly) {
boolean isStatic = Modifier.isStatic(field.getModifiers());
if (isStatic) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -29,7 +29,16 @@
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;

abstract class MethodHandleFieldAccessorImpl extends FieldAccessorImpl {
abstract sealed class MethodHandleFieldAccessorImpl extends FieldAccessorImpl
permits MethodHandleBooleanFieldAccessorImpl,
MethodHandleCharacterFieldAccessorImpl,
MethodHandleByteFieldAccessorImpl,
MethodHandleShortFieldAccessorImpl,
MethodHandleIntegerFieldAccessorImpl,
MethodHandleLongFieldAccessorImpl,
MethodHandleFloatFieldAccessorImpl,
MethodHandleDoubleFieldAccessorImpl,
MethodHandleObjectFieldAccessorImpl {
private static final int IS_READ_ONLY_BIT = 0x0001;
private static final int IS_STATIC_BIT = 0x0002;
private static final int NONZERO_BIT = 0x8000;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -30,7 +30,7 @@
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;

class MethodHandleFloatFieldAccessorImpl extends MethodHandleFieldAccessorImpl {
final class MethodHandleFloatFieldAccessorImpl extends MethodHandleFieldAccessorImpl {
static FieldAccessorImpl fieldAccessor(Field field, MethodHandle getter, MethodHandle setter, boolean isReadOnly) {
boolean isStatic = Modifier.isStatic(field.getModifiers());
if (isStatic) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -30,7 +30,7 @@
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;

class MethodHandleIntegerFieldAccessorImpl extends MethodHandleFieldAccessorImpl {
final class MethodHandleIntegerFieldAccessorImpl extends MethodHandleFieldAccessorImpl {
static FieldAccessorImpl fieldAccessor(Field field, MethodHandle getter, MethodHandle setter, boolean isReadOnly) {
boolean isStatic = Modifier.isStatic(field.getModifiers());
if (isStatic) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -30,7 +30,7 @@
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;

class MethodHandleLongFieldAccessorImpl extends MethodHandleFieldAccessorImpl {
final class MethodHandleLongFieldAccessorImpl extends MethodHandleFieldAccessorImpl {
static FieldAccessorImpl fieldAccessor(Field field, MethodHandle getter, MethodHandle setter, boolean isReadOnly) {
boolean isStatic = Modifier.isStatic(field.getModifiers());
if (isStatic) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -30,7 +30,7 @@
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;

class MethodHandleObjectFieldAccessorImpl extends MethodHandleFieldAccessorImpl {
final class MethodHandleObjectFieldAccessorImpl extends MethodHandleFieldAccessorImpl {
static FieldAccessorImpl fieldAccessor(Field field, MethodHandle getter, MethodHandle setter, boolean isReadOnly) {
boolean isStatic = Modifier.isStatic(field.getModifiers());
if (isStatic) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -30,7 +30,7 @@
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;

class MethodHandleShortFieldAccessorImpl extends MethodHandleFieldAccessorImpl {
final class MethodHandleShortFieldAccessorImpl extends MethodHandleFieldAccessorImpl {
static FieldAccessorImpl fieldAccessor(Field field, MethodHandle getter, MethodHandle setter, boolean isReadOnly) {
boolean isStatic = Modifier.isStatic(field.getModifiers());
if (isStatic) {
Expand Down
Loading