diff --git a/make/modules/java.base/Copy.gmk b/make/modules/java.base/Copy.gmk index fea544a47a132..7e3a0e9c3ab5e 100644 --- a/make/modules/java.base/Copy.gmk +++ b/make/modules/java.base/Copy.gmk @@ -123,46 +123,6 @@ TARGETS += $(JVMCFG) ################################################################################ -POLICY_SRC := $(TOPDIR)/src/java.base/share/conf/security/java.policy -POLICY_DST := $(CONF_DST_DIR)/security/java.policy - -POLICY_SRC_LIST := $(POLICY_SRC) - -$(POLICY_DST): $(POLICY_SRC_LIST) - $(call MakeTargetDir) - $(RM) $@ $@.tmp - $(foreach f, $(POLICY_SRC_LIST), $(CAT) $(f) >> $@.tmp;) - $(MV) $@.tmp $@ - -TARGETS += $(POLICY_DST) - -################################################################################ - -DEF_POLICY_SRC := $(TOPDIR)/src/java.base/share/lib/security/default.policy -DEF_POLICY_DST := $(LIB_DST_DIR)/security/default.policy - -DEF_POLICY_SRC_LIST := $(DEF_POLICY_SRC) -DEF_POLICY_SRC_LIST += $(CUSTOM_POLICY_SRC_LIST) - -ifeq ($(call isTargetOs, windows), true) - DEF_POLICY_SRC_LIST += $(TOPDIR)/src/java.base/$(OPENJDK_TARGET_OS)/lib/security/default.policy -endif - -# Allow imported modules to modify the java.policy -ifneq ($(IMPORT_MODULES_CONF), ) - DEF_POLICY_SRC_LIST += $(wildcard $(IMPORT_MODULES_CONF)/java.base/security/java.policy.extra) -endif - -$(DEF_POLICY_DST): $(DEF_POLICY_SRC_LIST) - $(call MakeTargetDir) - $(RM) $@ $@.tmp - $(foreach f, $(DEF_POLICY_SRC_LIST), $(CAT) $(f) >> $@.tmp;) - $(MV) $@.tmp $@ - -TARGETS += $(DEF_POLICY_DST) - -################################################################################ - # CACERTS_FILE is optionally set in configure to override the default cacerts # which is otherwise generated in Gendata-java.base.gmk CACERTS_DST := $(LIB_DST_DIR)/security/cacerts diff --git a/make/modules/java.rmi/Launcher.gmk b/make/modules/java.rmi/Launcher.gmk index 14b381a540ec3..8c335711da026 100644 --- a/make/modules/java.rmi/Launcher.gmk +++ b/make/modules/java.rmi/Launcher.gmk @@ -31,5 +31,4 @@ include LauncherCommon.gmk $(eval $(call SetupBuildLauncher, rmiregistry, \ MAIN_CLASS := sun.rmi.registry.RegistryImpl, \ - JAVA_ARGS := -Djava.security.manager=allow, \ )) diff --git a/src/hotspot/share/classfile/dictionary.cpp b/src/hotspot/share/classfile/dictionary.cpp index f25c453582fb8..eecfc9e88a0fd 100644 --- a/src/hotspot/share/classfile/dictionary.cpp +++ b/src/hotspot/share/classfile/dictionary.cpp @@ -347,68 +347,6 @@ void Dictionary::check_package_access(InstanceKlass* klass, assert(class_loader() != nullptr, "Should not call this"); assert(protection_domain() != nullptr, "Should not call this"); - - if (!java_lang_System::allow_security_manager()) { - // No need for any further checking. Package access always allowed. - return; - } - - if (is_in_package_access_cache(THREAD, klass->name(), protection_domain)) { - // No need to check again. - return; - } - - // We only have to call checkPackageAccess if there's a security manager installed. - if (java_lang_System::has_security_manager()) { - - // This handle and the class_loader handle passed in keeps this class from - // being unloaded through several GC points. - // The class_loader handle passed in is the initiating loader. - Handle mirror(THREAD, klass->java_mirror()); - - // Now we have to call back to java to check if the initating class has access - InstanceKlass* system_loader = vmClasses::ClassLoader_klass(); - JavaValue result(T_VOID); - JavaCalls::call_special(&result, - class_loader, - system_loader, - vmSymbols::checkPackageAccess_name(), - vmSymbols::class_protectiondomain_signature(), - mirror, - protection_domain, - THREAD); - - LogTarget(Debug, protectiondomain) lt; - if (lt.is_enabled()) { - ResourceMark rm(THREAD); - // Print out trace information - LogStream ls(lt); - ls.print_cr("Checking package access"); - ls.print("class loader: "); - class_loader()->print_value_on(&ls); - ls.print(" protection domain: "); - protection_domain()->print_value_on(&ls); - ls.print(" loading: "); klass->print_value_on(&ls); - if (HAS_PENDING_EXCEPTION) { - ls.print_cr(" DENIED !!!!!!!!!!!!!!!!!!!!!"); - } else { - ls.print_cr(" granted"); - } - } - - if (HAS_PENDING_EXCEPTION) return; - } - - // If no exception has been thrown, we have checked that the protection_domain can access - // this klass. Always add it to the cache (even if no SecurityManager is installed yet). - // - // This ensures that subsequent calls to Dictionary::find(THREAD, klass->name(), protection_domain) - // will always succeed. I.e., a new SecurityManager installed in the future cannot retroactively - // revoke the granted access. - { - MutexLocker mu(THREAD, SystemDictionary_lock); - add_to_package_access_cache(THREAD, klass, protection_domain); - } } // During class loading we may have cached a protection domain that has diff --git a/src/hotspot/share/classfile/javaClasses.cpp b/src/hotspot/share/classfile/javaClasses.cpp index 3dce1a343d896..c91ca6bf134c2 100644 --- a/src/hotspot/share/classfile/javaClasses.cpp +++ b/src/hotspot/share/classfile/javaClasses.cpp @@ -1599,7 +1599,6 @@ oop java_lang_Thread_Constants::get_VTHREAD_GROUP() { int java_lang_Thread::_holder_offset; int java_lang_Thread::_name_offset; int java_lang_Thread::_contextClassLoader_offset; -int java_lang_Thread::_inheritedAccessControlContext_offset; int java_lang_Thread::_eetop_offset; int java_lang_Thread::_jvmti_thread_state_offset; int java_lang_Thread::_jvmti_VTMS_transition_disable_count_offset; @@ -1616,7 +1615,6 @@ JFR_ONLY(int java_lang_Thread::_jfr_epoch_offset;) macro(_holder_offset, k, "holder", thread_fieldholder_signature, false); \ macro(_name_offset, k, vmSymbols::name_name(), string_signature, false); \ macro(_contextClassLoader_offset, k, vmSymbols::contextClassLoader_name(), classloader_signature, false); \ - macro(_inheritedAccessControlContext_offset, k, vmSymbols::inheritedAccessControlContext_name(), accesscontrolcontext_signature, false); \ macro(_eetop_offset, k, "eetop", long_signature, false); \ macro(_interrupted_offset, k, "interrupted", bool_signature, false); \ macro(_interruptLock_offset, k, "interruptLock", object_signature, false); \ @@ -1793,10 +1791,6 @@ oop java_lang_Thread::context_class_loader(oop java_thread) { return java_thread->obj_field(_contextClassLoader_offset); } -oop java_lang_Thread::inherited_access_control_context(oop java_thread) { - return java_thread->obj_field(_inheritedAccessControlContext_offset); -} - jlong java_lang_Thread::stackSize(oop java_thread) { GET_FIELDHOLDER_FIELD(java_thread, stackSize, 0); @@ -4782,17 +4776,11 @@ oop java_lang_ClassLoader::unnamedModule(oop loader) { int java_lang_System::_static_in_offset; int java_lang_System::_static_out_offset; int java_lang_System::_static_err_offset; -int java_lang_System::_static_security_offset; -int java_lang_System::_static_allow_security_offset; -int java_lang_System::_static_never_offset; #define SYSTEM_FIELDS_DO(macro) \ macro(_static_in_offset, k, "in", input_stream_signature, true); \ macro(_static_out_offset, k, "out", print_stream_signature, true); \ - macro(_static_err_offset, k, "err", print_stream_signature, true); \ - macro(_static_security_offset, k, "security", security_manager_signature, true); \ - macro(_static_allow_security_offset, k, "allowSecurityManager", int_signature, true); \ - macro(_static_never_offset, k, "NEVER", int_signature, true) + macro(_static_err_offset, k, "err", print_stream_signature, true); void java_lang_System::compute_offsets() { InstanceKlass* k = vmClasses::System_klass(); @@ -4802,21 +4790,12 @@ void java_lang_System::compute_offsets() { // This field tells us that a security manager can never be installed so we // can completely skip populating the ProtectionDomainCacheTable. bool java_lang_System::allow_security_manager() { - static int initialized = false; - static bool allowed = true; // default - if (!initialized) { - oop base = vmClasses::System_klass()->static_field_base_raw(); - int never = base->int_field(_static_never_offset); - allowed = (base->int_field(_static_allow_security_offset) != never); - initialized = true; - } - return allowed; + return false; } // This field tells us that a security manager is installed. bool java_lang_System::has_security_manager() { - oop base = vmClasses::System_klass()->static_field_base_raw(); - return base->obj_field(_static_security_offset) != nullptr; + return false; } #if INCLUDE_CDS diff --git a/src/hotspot/share/classfile/javaClasses.hpp b/src/hotspot/share/classfile/javaClasses.hpp index 6ab73b161f4f0..8e8baa8b57b59 100644 --- a/src/hotspot/share/classfile/javaClasses.hpp +++ b/src/hotspot/share/classfile/javaClasses.hpp @@ -358,7 +358,6 @@ class java_lang_Thread : AllStatic { static int _holder_offset; static int _name_offset; static int _contextClassLoader_offset; - static int _inheritedAccessControlContext_offset; static int _eetop_offset; static int _jvmti_thread_state_offset; static int _jvmti_VTMS_transition_disable_count_offset; @@ -405,8 +404,6 @@ class java_lang_Thread : AllStatic { static void set_daemon(oop java_thread); // Context ClassLoader static oop context_class_loader(oop java_thread); - // Control context - static oop inherited_access_control_context(oop java_thread); // Stack size hint static jlong stackSize(oop java_thread); // Thread ID diff --git a/src/hotspot/share/classfile/vmSymbols.hpp b/src/hotspot/share/classfile/vmSymbols.hpp index d8018cd0c8af2..5db725ab1af32 100644 --- a/src/hotspot/share/classfile/vmSymbols.hpp +++ b/src/hotspot/share/classfile/vmSymbols.hpp @@ -439,10 +439,8 @@ class SerializeClosure; template(getProperty_name, "getProperty") \ template(context_name, "context") \ template(contextClassLoader_name, "contextClassLoader") \ - template(inheritedAccessControlContext_name, "inheritedAccessControlContext") \ template(getClassContext_name, "getClassContext") \ template(wait_name, "wait0") \ - template(checkPackageAccess_name, "checkPackageAccess") \ template(forName_name, "forName") \ template(forName0_name, "forName0") \ template(isJavaIdentifierStart_name, "isJavaIdentifierStart") \ diff --git a/src/hotspot/share/include/jvm.h b/src/hotspot/share/include/jvm.h index 23040aa1dcd45..6935a6d7c4a98 100644 --- a/src/hotspot/share/include/jvm.h +++ b/src/hotspot/share/include/jvm.h @@ -723,13 +723,6 @@ JNIEXPORT jbyte JNICALL JVM_ConstantPoolGetTagAt JNIEXPORT jobjectArray JNICALL JVM_GetMethodParameters(JNIEnv *env, jobject method); -/* - * java.security.* - */ - -JNIEXPORT jobject JNICALL -JVM_GetInheritedAccessControlContext(JNIEnv *env, jclass cls); - /* * Ensure that code doing a stackwalk and using javaVFrame::locals() to * get the value will see a materialized value and not a scalar-replaced @@ -741,9 +734,6 @@ JVM_GetInheritedAccessControlContext(JNIEnv *env, jclass cls); JNIEXPORT void JNICALL JVM_EnsureMaterializedForStackWalk_func(JNIEnv* env, jobject vthread, jobject value); -JNIEXPORT jobject JNICALL -JVM_GetStackAccessControlContext(JNIEnv *env, jclass cls); - /* * Signal support, used to implement the shutdown sequence. Every VM must * support JVM_SIGINT and JVM_SIGTERM, raising the former for user interrupts diff --git a/src/hotspot/share/prims/jvm.cpp b/src/hotspot/share/prims/jvm.cpp index f0f14a0503162..6a1ddb9bab7c5 100644 --- a/src/hotspot/share/prims/jvm.cpp +++ b/src/hotspot/share/prims/jvm.cpp @@ -1269,87 +1269,6 @@ JVM_ENTRY(jobject, JVM_GetProtectionDomain(JNIEnv *env, jclass cls)) JVM_END -// Returns the inherited_access_control_context field of the running thread. -JVM_ENTRY(jobject, JVM_GetInheritedAccessControlContext(JNIEnv *env, jclass cls)) - oop result = java_lang_Thread::inherited_access_control_context(thread->threadObj()); - return JNIHandles::make_local(THREAD, result); -JVM_END - -JVM_ENTRY(jobject, JVM_GetStackAccessControlContext(JNIEnv *env, jclass cls)) - if (!UsePrivilegedStack) return nullptr; - - ResourceMark rm(THREAD); - GrowableArray* local_array = new GrowableArray(12); - JvmtiVMObjectAllocEventCollector oam; - - // count the protection domains on the execution stack. We collapse - // duplicate consecutive protection domains into a single one, as - // well as stopping when we hit a privileged frame. - - oop previous_protection_domain = nullptr; - Handle privileged_context(thread, nullptr); - bool is_privileged = false; - oop protection_domain = nullptr; - - // Iterate through Java frames - vframeStream vfst(thread); - for(; !vfst.at_end(); vfst.next()) { - // get method of frame - Method* method = vfst.method(); - - // stop at the first privileged frame - if (method->method_holder() == vmClasses::AccessController_klass() && - method->name() == vmSymbols::executePrivileged_name()) - { - // this frame is privileged - is_privileged = true; - - javaVFrame *priv = vfst.asJavaVFrame(); // executePrivileged - - StackValueCollection* locals = priv->locals(); - StackValue* ctx_sv = locals->at(1); // AccessControlContext context - StackValue* clr_sv = locals->at(2); // Class caller - assert(!ctx_sv->obj_is_scalar_replaced(), "found scalar-replaced object"); - assert(!clr_sv->obj_is_scalar_replaced(), "found scalar-replaced object"); - privileged_context = ctx_sv->get_obj(); - Handle caller = clr_sv->get_obj(); - - Klass *caller_klass = java_lang_Class::as_Klass(caller()); - protection_domain = caller_klass->protection_domain(); - } else { - protection_domain = method->method_holder()->protection_domain(); - } - - if ((previous_protection_domain != protection_domain) && (protection_domain != nullptr)) { - local_array->push(Handle(thread, protection_domain)); - previous_protection_domain = protection_domain; - } - - if (is_privileged) break; - } - - - // either all the domains on the stack were system domains, or - // we had a privileged system domain - if (local_array->is_empty()) { - if (is_privileged && privileged_context.is_null()) return nullptr; - - oop result = java_security_AccessControlContext::create(objArrayHandle(), is_privileged, privileged_context, CHECK_NULL); - return JNIHandles::make_local(THREAD, result); - } - - objArrayOop context = oopFactory::new_objArray(vmClasses::ProtectionDomain_klass(), - local_array->length(), CHECK_NULL); - objArrayHandle h_context(thread, context); - for (int index = 0; index < local_array->length(); index++) { - h_context->obj_at_put(index, local_array->at(index)()); - } - - oop result = java_security_AccessControlContext::create(h_context, is_privileged, privileged_context, CHECK_NULL); - - return JNIHandles::make_local(THREAD, result); -JVM_END - class ScopedValueBindingsResolver { public: InstanceKlass* Carrier_klass; diff --git a/src/hotspot/share/runtime/globals.hpp b/src/hotspot/share/runtime/globals.hpp index cca58b0c22e26..70b537bf2d731 100644 --- a/src/hotspot/share/runtime/globals.hpp +++ b/src/hotspot/share/runtime/globals.hpp @@ -681,9 +681,6 @@ const int ObjectAlignmentInBytes = 8; develop(bool, PrintCodeCacheExtension, false, \ "Print extension of code cache") \ \ - develop(bool, UsePrivilegedStack, true, \ - "Enable the security JVM functions") \ - \ product(bool, ClassUnloading, true, \ "Do unloading of classes") \ \ diff --git a/src/java.base/share/classes/java/io/File.java b/src/java.base/share/classes/java/io/File.java index 61c15bdd15c0b..b8eda9dcf8315 100644 --- a/src/java.base/share/classes/java/io/File.java +++ b/src/java.base/share/classes/java/io/File.java @@ -556,9 +556,6 @@ public boolean isAbsolute() { * @return The absolute pathname string denoting the same file or * directory as this abstract pathname * - * @throws SecurityException - * If a required system property value cannot be accessed. - * * @see java.io.File#isAbsolute() */ public String getAbsolutePath() { @@ -572,9 +569,6 @@ public String getAbsolutePath() { * @return The absolute abstract pathname denoting the same file or * directory as this abstract pathname * - * @throws SecurityException - * If a required system property value cannot be accessed. - * * @since 1.2 */ public File getAbsoluteFile() { @@ -614,12 +608,6 @@ public File getAbsoluteFile() { * construction of the canonical pathname may require * filesystem queries * - * @throws SecurityException - * If a required system property value cannot be accessed, or - * if a security manager exists and its {@link - * java.lang.SecurityManager#checkRead} method denies - * read access to the file - * * @since 1.1 * @see Path#toRealPath */ @@ -642,12 +630,6 @@ public String getCanonicalPath() throws IOException { * construction of the canonical pathname may require * filesystem queries * - * @throws SecurityException - * If a required system property value cannot be accessed, or - * if a security manager exists and its {@link - * java.lang.SecurityManager#checkRead} method denies - * read access to the file - * * @since 1.2 * @see Path#toRealPath */ @@ -736,8 +718,6 @@ public URL toURL() throws MalformedURLException { * @return An absolute, hierarchical URI with a scheme equal to * {@code "file"}, a path representing this abstract pathname, * and undefined authority, query, and fragment components - * @throws SecurityException If a required system property value cannot - * be accessed. * * @see #File(java.net.URI) * @see java.net.URI @@ -769,11 +749,6 @@ public URI toURI() { * @return {@code true} if and only if the file specified by this * abstract pathname exists and can be read by the * application; {@code false} otherwise - * - * @throws SecurityException - * If a security manager exists and its {@link - * java.lang.SecurityManager#checkRead(java.lang.String)} - * method denies read access to the file */ public boolean canRead() { @SuppressWarnings("removal") @@ -798,11 +773,6 @@ public boolean canRead() { * contains a file denoted by this abstract pathname and * the application is allowed to write to the file; * {@code false} otherwise. - * - * @throws SecurityException - * If a security manager exists and its {@link - * java.lang.SecurityManager#checkWrite(java.lang.String)} - * method denies write access to the file */ public boolean canWrite() { @SuppressWarnings("removal") @@ -822,11 +792,6 @@ public boolean canWrite() { * * @return {@code true} if and only if the file or directory denoted * by this abstract pathname exists; {@code false} otherwise - * - * @throws SecurityException - * If a security manager exists and its {@link - * java.lang.SecurityManager#checkRead(java.lang.String)} - * method denies read access to the file or directory */ public boolean exists() { @SuppressWarnings("removal") @@ -853,11 +818,6 @@ public boolean exists() { * @return {@code true} if and only if the file denoted by this * abstract pathname exists and is a directory; * {@code false} otherwise - * - * @throws SecurityException - * If a security manager exists and its {@link - * java.lang.SecurityManager#checkRead(java.lang.String)} - * method denies read access to the file */ public boolean isDirectory() { @SuppressWarnings("removal") @@ -886,11 +846,6 @@ public boolean isDirectory() { * @return {@code true} if and only if the file denoted by this * abstract pathname exists and is a normal file; * {@code false} otherwise - * - * @throws SecurityException - * If a security manager exists and its {@link - * java.lang.SecurityManager#checkRead(java.lang.String)} - * method denies read access to the file */ public boolean isFile() { @SuppressWarnings("removal") @@ -923,11 +878,6 @@ public boolean isFile() { * abstract pathname is hidden according to the conventions of the * underlying platform * - * @throws SecurityException - * If a security manager exists and its {@link - * java.lang.SecurityManager#checkRead(java.lang.String)} - * method denies read access to the file - * * @since 1.2 */ public boolean isHidden() { @@ -968,11 +918,6 @@ public boolean isHidden() { * file does not exist or if an I/O error occurs. The value may * be negative indicating the number of milliseconds before the * epoch - * - * @throws SecurityException - * If a security manager exists and its {@link - * java.lang.SecurityManager#checkRead(java.lang.String)} - * method denies read access to the file */ public long lastModified() { @SuppressWarnings("removal") @@ -1000,11 +945,6 @@ public long lastModified() { * pathname, or {@code 0L} if the file does not exist. Some * operating systems may return {@code 0L} for pathnames * denoting system-dependent entities such as devices or pipes. - * - * @throws SecurityException - * If a security manager exists and its {@link - * java.lang.SecurityManager#checkRead(java.lang.String)} - * method denies read access to the file */ public long length() { @SuppressWarnings("removal") @@ -1040,11 +980,6 @@ public long length() { * @throws IOException * If an I/O error occurred * - * @throws SecurityException - * If a security manager exists and its {@link - * java.lang.SecurityManager#checkWrite(java.lang.String)} - * method denies write access to the file - * * @since 1.2 */ public boolean createNewFile() throws IOException { @@ -1070,11 +1005,6 @@ public boolean createNewFile() throws IOException { * * @return {@code true} if and only if the file or directory is * successfully deleted; {@code false} otherwise - * - * @throws SecurityException - * If a security manager exists and its {@link - * java.lang.SecurityManager#checkDelete} method denies - * delete access to the file */ public boolean delete() { @SuppressWarnings("removal") @@ -1108,11 +1038,6 @@ public boolean delete() { * {@link java.nio.channels.FileLock FileLock} * facility should be used instead. * - * @throws SecurityException - * If a security manager exists and its {@link - * java.lang.SecurityManager#checkDelete} method denies - * delete access to the file - * * @see #delete * * @since 1.2 @@ -1155,11 +1080,6 @@ public void deleteOnExit() { * empty if the directory is empty. Returns {@code null} if * this abstract pathname does not denote a directory, or if an * I/O error occurs. - * - * @throws SecurityException - * If a security manager exists and its {@link - * SecurityManager#checkRead(String)} method denies read access to - * the directory */ public String[] list() { return normalizedList(); @@ -1175,11 +1095,6 @@ public String[] list() { * empty if the directory is empty. Returns {@code null} if * this abstract pathname does not denote a directory, or if an * I/O error occurs. - * - * @throws SecurityException - * If a security manager exists and its {@link - * SecurityManager#checkRead(String)} method denies read access to - * the directory */ private final String[] normalizedList() { @SuppressWarnings("removal") @@ -1223,11 +1138,6 @@ private final String[] normalizedList() { * Returns {@code null} if this abstract pathname does not denote * a directory, or if an I/O error occurs. * - * @throws SecurityException - * If a security manager exists and its {@link - * SecurityManager#checkRead(String)} method denies read access to - * the directory - * * @see java.nio.file.Files#newDirectoryStream(Path,String) */ public String[] list(FilenameFilter filter) { @@ -1275,11 +1185,6 @@ public String[] list(FilenameFilter filter) { * {@code null} if this abstract pathname does not denote a * directory, or if an I/O error occurs. * - * @throws SecurityException - * If a security manager exists and its {@link - * SecurityManager#checkRead(String)} method denies read access to - * the directory - * * @since 1.2 */ public File[] listFiles() { @@ -1315,11 +1220,6 @@ public File[] listFiles() { * {@code null} if this abstract pathname does not denote a * directory, or if an I/O error occurs. * - * @throws SecurityException - * If a security manager exists and its {@link - * SecurityManager#checkRead(String)} method denies read access to - * the directory - * * @since 1.2 * @see java.nio.file.Files#newDirectoryStream(Path,String) */ @@ -1353,11 +1253,6 @@ public File[] listFiles(FilenameFilter filter) { * {@code null} if this abstract pathname does not denote a * directory, or if an I/O error occurs. * - * @throws SecurityException - * If a security manager exists and its {@link - * SecurityManager#checkRead(String)} method denies read access to - * the directory - * * @since 1.2 * @see java.nio.file.Files#newDirectoryStream(Path,java.nio.file.DirectoryStream.Filter) */ @@ -1378,11 +1273,6 @@ public File[] listFiles(FileFilter filter) { * * @return {@code true} if and only if the directory was * created; {@code false} otherwise - * - * @throws SecurityException - * If a security manager exists and its {@link - * java.lang.SecurityManager#checkWrite(java.lang.String)} - * method does not permit the named directory to be created */ public boolean mkdir() { @SuppressWarnings("removal") @@ -1405,16 +1295,6 @@ public boolean mkdir() { * @return {@code true} if and only if the directory was created, * along with all necessary parent directories; {@code false} * otherwise - * - * @throws SecurityException - * If a security manager exists and its {@link - * java.lang.SecurityManager#checkRead(java.lang.String)} - * method does not permit verification of the existence of the - * named directory and all necessary parent directories; or if - * the {@link - * java.lang.SecurityManager#checkWrite(java.lang.String)} - * method does not permit the named directory and all necessary - * parent directories to be created */ public boolean mkdirs() { if (exists()) { @@ -1458,11 +1338,6 @@ public boolean mkdirs() { * @return {@code true} if and only if the renaming succeeded; * {@code false} otherwise * - * @throws SecurityException - * If a security manager exists and its {@link - * java.lang.SecurityManager#checkWrite(java.lang.String)} - * method denies write access to either the old or new pathnames - * * @throws NullPointerException * If parameter {@code dest} is {@code null} */ @@ -1501,11 +1376,6 @@ public boolean renameTo(File dest) { * * @throws IllegalArgumentException If the argument is negative * - * @throws SecurityException - * If a security manager exists and its {@link - * java.lang.SecurityManager#checkWrite(java.lang.String)} - * method denies write access to the named file - * * @since 1.2 */ public boolean setLastModified(long time) { @@ -1533,11 +1403,6 @@ public boolean setLastModified(long time) { * @return {@code true} if and only if the operation succeeded; * {@code false} otherwise * - * @throws SecurityException - * If a security manager exists and its {@link - * java.lang.SecurityManager#checkWrite(java.lang.String)} - * method denies write access to the named file - * * @since 1.2 */ public boolean setReadOnly() { @@ -1577,11 +1442,6 @@ public boolean setReadOnly() { * operation will fail if the user does not have permission to change * the access permissions of this abstract pathname. * - * @throws SecurityException - * If a security manager exists and its {@link - * java.lang.SecurityManager#checkWrite(java.lang.String)} - * method denies write access to the named file - * * @since 1.6 */ public boolean setWritable(boolean writable, boolean ownerOnly) { @@ -1617,11 +1477,6 @@ public boolean setWritable(boolean writable, boolean ownerOnly) { * operation will fail if the user does not have permission to * change the access permissions of this abstract pathname. * - * @throws SecurityException - * If a security manager exists and its {@link - * java.lang.SecurityManager#checkWrite(java.lang.String)} - * method denies write access to the file - * * @since 1.6 */ public boolean setWritable(boolean writable) { @@ -1659,11 +1514,6 @@ public boolean setWritable(boolean writable) { * fails, or the value of the {@code readable} parameter if * setting the read permission is not supported. * - * @throws SecurityException - * If a security manager exists and its {@link - * java.lang.SecurityManager#checkWrite(java.lang.String)} - * method denies write access to the file - * * @since 1.6 */ public boolean setReadable(boolean readable, boolean ownerOnly) { @@ -1705,11 +1555,6 @@ public boolean setReadable(boolean readable, boolean ownerOnly) { * fails, or the value of the {@code readable} parameter if * setting the read permission is not supported. * - * @throws SecurityException - * If a security manager exists and its {@link - * java.lang.SecurityManager#checkWrite(java.lang.String)} - * method denies write access to the file - * * @since 1.6 */ public boolean setReadable(boolean readable) { @@ -1747,11 +1592,6 @@ public boolean setReadable(boolean readable) { * fails, or the value of the {@code executable} parameter if * setting the execute permission is not supported. * - * @throws SecurityException - * If a security manager exists and its {@link - * java.lang.SecurityManager#checkWrite(java.lang.String)} - * method denies write access to the file - * * @since 1.6 */ public boolean setExecutable(boolean executable, boolean ownerOnly) { @@ -1793,11 +1633,6 @@ public boolean setExecutable(boolean executable, boolean ownerOnly) { * fails, or the value of the {@code executable} parameter if * setting the execute permission is not supported. * - * @throws SecurityException - * If a security manager exists and its {@link - * java.lang.SecurityManager#checkWrite(java.lang.String)} - * method denies write access to the file - * * @since 1.6 */ public boolean setExecutable(boolean executable) { @@ -1814,11 +1649,6 @@ public boolean setExecutable(boolean executable) { * @return {@code true} if and only if the abstract pathname exists * and the application is allowed to execute the file * - * @throws SecurityException - * If a security manager exists and its {@link - * java.lang.SecurityManager#checkExec(java.lang.String)} - * method denies execute access to the file - * * @since 1.6 */ public boolean canExecute() { @@ -1850,12 +1680,6 @@ public boolean canExecute() { * machine will begin with one of the roots returned by this method. * There is no guarantee that a root directory can be accessed. * - *

Unlike most methods in this class, this method does not throw - * security exceptions. If a security manager exists and its {@link - * SecurityManager#checkRead(String)} method denies read access to a - * particular root directory, then that directory will not appear in the - * result. - * * @implNote * Windows platforms, for example, have a root directory * for each active drive; UNIX platforms have a single root directory, @@ -1898,12 +1722,6 @@ public static File[] listRoots() { * abstract pathname does not name a partition or if the size * cannot be obtained * - * @throws SecurityException - * If a security manager has been installed and it denies - * {@link RuntimePermission}{@code ("getFileSystemAttributes")} - * or its {@link SecurityManager#checkRead(String)} method denies - * read access to the file named by this abstract pathname - * * @since 1.6 * @see FileStore#getTotalSpace */ @@ -1942,12 +1760,6 @@ public long getTotalSpace() { * equal to the total file system size returned by * {@link #getTotalSpace}. * - * @throws SecurityException - * If a security manager has been installed and it denies - * {@link RuntimePermission}{@code ("getFileSystemAttributes")} - * or its {@link SecurityManager#checkRead(String)} method denies - * read access to the file named by this abstract pathname - * * @since 1.6 * @see FileStore#getUnallocatedSpace */ @@ -1989,12 +1801,6 @@ public long getFreeSpace() { * is not available, this method will be equivalent to a call to * {@link #getFreeSpace}. * - * @throws SecurityException - * If a security manager has been installed and it denies - * {@link RuntimePermission}{@code ("getFileSystemAttributes")} - * or its {@link SecurityManager#checkRead(String)} method denies - * read access to the file named by this abstract pathname - * * @since 1.6 * @see FileStore#getUsableSpace */ @@ -2176,11 +1982,6 @@ static File generateFile(String prefix, String suffix, File dir) * @throws IOException * If a file could not be created * - * @throws SecurityException - * If a security manager exists and its {@link - * java.lang.SecurityManager#checkWrite(java.lang.String)} - * method does not allow a file to be created - * * @since 1.2 */ public static File createTempFile(String prefix, String suffix, @@ -2250,11 +2051,6 @@ public static File createTempFile(String prefix, String suffix, * * @throws IOException If a file could not be created * - * @throws SecurityException - * If a security manager exists and its {@link - * java.lang.SecurityManager#checkWrite(java.lang.String)} - * method does not allow a file to be created - * * @since 1.2 * @see java.nio.file.Files#createTempDirectory(String,FileAttribute[]) */ diff --git a/src/java.base/share/classes/java/io/FileInputStream.java b/src/java.base/share/classes/java/io/FileInputStream.java index 4210a0f56b6b6..e429faec09bd0 100644 --- a/src/java.base/share/classes/java/io/FileInputStream.java +++ b/src/java.base/share/classes/java/io/FileInputStream.java @@ -95,11 +95,6 @@ public class FileInputStream extends InputStream * object is created to represent this file * connection. *

- * First, if there is a security - * manager, its {@code checkRead} method - * is called with the {@code name} argument - * as its argument. - *

* If the named file does not exist, is a directory rather than a regular * file, or for some other reason cannot be opened for reading then a * {@code FileNotFoundException} is thrown. @@ -109,10 +104,6 @@ public class FileInputStream extends InputStream * is a directory rather than a regular file, * or for some other reason cannot be opened for * reading. - * @throws SecurityException if a security manager exists and its - * {@code checkRead} method denies read access - * to the file. - * @see java.lang.SecurityManager#checkRead(java.lang.String) */ public FileInputStream(String name) throws FileNotFoundException { this(name != null ? new File(name) : null); @@ -126,11 +117,6 @@ public FileInputStream(String name) throws FileNotFoundException { * A new {@code FileDescriptor} object * is created to represent this file connection. *

- * First, if there is a security manager, - * its {@code checkRead} method is called - * with the path represented by the {@code file} - * argument as its argument. - *

* If the named file does not exist, is a directory rather than a regular * file, or for some other reason cannot be opened for reading then a * {@code FileNotFoundException} is thrown. @@ -140,10 +126,7 @@ public FileInputStream(String name) throws FileNotFoundException { * is a directory rather than a regular file, * or for some other reason cannot be opened for * reading. - * @throws SecurityException if a security manager exists and its - * {@code checkRead} method denies read access to the file. * @see java.io.File#getPath() - * @see java.lang.SecurityManager#checkRead(java.lang.String) */ @SuppressWarnings("this-escape") public FileInputStream(File file) throws FileNotFoundException { @@ -171,11 +154,6 @@ public FileInputStream(File file) throws FileNotFoundException { * {@code fdObj}, which represents an existing connection to an * actual file in the file system. *

- * If there is a security manager, its {@code checkRead} method is - * called with the file descriptor {@code fdObj} as its argument to - * see if it's ok to read the file descriptor. If read access is denied - * to the file descriptor a {@code SecurityException} is thrown. - *

* If {@code fdObj} is null then a {@code NullPointerException} * is thrown. *

@@ -185,10 +163,6 @@ public FileInputStream(File file) throws FileNotFoundException { * I/O on the stream, an {@code IOException} is thrown. * * @param fdObj the file descriptor to be opened for reading. - * @throws SecurityException if a security manager exists and its - * {@code checkRead} method denies read access to the - * file descriptor. - * @see SecurityManager#checkRead(java.io.FileDescriptor) */ @SuppressWarnings("this-escape") public FileInputStream(FileDescriptor fdObj) { diff --git a/src/java.base/share/classes/java/io/FileOutputStream.java b/src/java.base/share/classes/java/io/FileOutputStream.java index ff15e831b9530..557bea0c3fc51 100644 --- a/src/java.base/share/classes/java/io/FileOutputStream.java +++ b/src/java.base/share/classes/java/io/FileOutputStream.java @@ -103,9 +103,6 @@ public class FileOutputStream extends OutputStream * A new {@code FileDescriptor} object is * created to represent this file connection. *

- * First, if there is a security manager, its {@code checkWrite} - * method is called with {@code name} as its argument. - *

* If the file exists but is a directory rather than a regular file, does * not exist but cannot be created, or cannot be opened for any other * reason then a {@code FileNotFoundException} is thrown. @@ -118,10 +115,6 @@ public class FileOutputStream extends OutputStream * @throws FileNotFoundException if the file exists but is a directory * rather than a regular file, does not exist but cannot * be created, or cannot be opened for any other reason - * @throws SecurityException if a security manager exists and its - * {@code checkWrite} method denies write access - * to the file. - * @see java.lang.SecurityManager#checkWrite(java.lang.String) */ public FileOutputStream(String name) throws FileNotFoundException { this(name != null ? new File(name) : null, false); @@ -137,9 +130,6 @@ public FileOutputStream(String name) throws FileNotFoundException { * A new {@code FileDescriptor} object is created to represent this * file connection. *

- * First, if there is a security manager, its {@code checkWrite} - * method is called with {@code name} as its argument. - *

* If the file exists but is a directory rather than a regular file, does * not exist but cannot be created, or cannot be opened for any other * reason then a {@code FileNotFoundException} is thrown. @@ -150,10 +140,6 @@ public FileOutputStream(String name) throws FileNotFoundException { * @throws FileNotFoundException if the file exists but is a directory * rather than a regular file, does not exist but cannot * be created, or cannot be opened for any other reason. - * @throws SecurityException if a security manager exists and its - * {@code checkWrite} method denies write access - * to the file. - * @see java.lang.SecurityManager#checkWrite(java.lang.String) * @since 1.1 */ public FileOutputStream(String name, boolean append) @@ -171,10 +157,6 @@ public FileOutputStream(String name, boolean append) * A new {@code FileDescriptor} object is * created to represent this file connection. *

- * First, if there is a security manager, its {@code checkWrite} - * method is called with the path represented by the {@code file} - * argument as its argument. - *

* If the file exists but is a directory rather than a regular file, does * not exist but cannot be created, or cannot be opened for any other * reason then a {@code FileNotFoundException} is thrown. @@ -183,12 +165,7 @@ public FileOutputStream(String name, boolean append) * @throws FileNotFoundException if the file exists but is a directory * rather than a regular file, does not exist but cannot * be created, or cannot be opened for any other reason - * @throws SecurityException if a security manager exists and its - * {@code checkWrite} method denies write access - * to the file. * @see java.io.File#getPath() - * @see java.lang.SecurityException - * @see java.lang.SecurityManager#checkWrite(java.lang.String) */ public FileOutputStream(File file) throws FileNotFoundException { this(file, false); @@ -205,10 +182,6 @@ public FileOutputStream(File file) throws FileNotFoundException { * A new {@code FileDescriptor} object is created to represent this * file connection. *

- * First, if there is a security manager, its {@code checkWrite} - * method is called with the path represented by the {@code file} - * argument as its argument. - *

* If the file exists but is a directory rather than a regular file, does * not exist but cannot be created, or cannot be opened for any other * reason then a {@code FileNotFoundException} is thrown. @@ -219,12 +192,7 @@ public FileOutputStream(File file) throws FileNotFoundException { * @throws FileNotFoundException if the file exists but is a directory * rather than a regular file, does not exist but cannot * be created, or cannot be opened for any other reason - * @throws SecurityException if a security manager exists and its - * {@code checkWrite} method denies write access - * to the file. * @see java.io.File#getPath() - * @see java.lang.SecurityException - * @see java.lang.SecurityManager#checkWrite(java.lang.String) * @since 1.4 */ @SuppressWarnings("this-escape") @@ -256,10 +224,6 @@ public FileOutputStream(File file, boolean append) * descriptor, which represents an existing connection to an actual * file in the file system. *

- * First, if there is a security manager, its {@code checkWrite} - * method is called with the file descriptor {@code fdObj} - * argument as its argument. - *

* If {@code fdObj} is null then a {@code NullPointerException} * is thrown. *

@@ -269,10 +233,6 @@ public FileOutputStream(File file, boolean append) * I/O on the stream, an {@code IOException} is thrown. * * @param fdObj the file descriptor to be opened for writing - * @throws SecurityException if a security manager exists and its - * {@code checkWrite} method denies - * write access to the file descriptor - * @see java.lang.SecurityManager#checkWrite(java.io.FileDescriptor) */ @SuppressWarnings("this-escape") public FileOutputStream(FileDescriptor fdObj) { diff --git a/src/java.base/share/classes/java/io/FilePermission.java b/src/java.base/share/classes/java/io/FilePermission.java index 808c42931434d..b11e0dd25bebe 100644 --- a/src/java.base/share/classes/java/io/FilePermission.java +++ b/src/java.base/share/classes/java/io/FilePermission.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2024, 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 @@ -61,39 +61,15 @@ * (recursively) all files and subdirectories contained in the current * directory. *

- * The actions to be granted are passed to the constructor in a string containing + * The actions are passed to the constructor in a string containing * a list of one or more comma-separated keywords. The possible keywords are - * "read", "write", "execute", "delete", and "readlink". Their meaning is - * defined as follows: - * - *

- *
read
read permission - *
write
write permission - *
execute - *
execute permission. Allows {@code Runtime.exec} to - * be called. Corresponds to {@code SecurityManager.checkExec}. - *
delete - *
delete permission. Allows {@code File.delete} to - * be called. Corresponds to {@code SecurityManager.checkDelete}. - *
readlink - *
read link permission. Allows the target of a - * symbolic link - * to be read by invoking the {@link java.nio.file.Files#readSymbolicLink - * readSymbolicLink } method. - *
+ * "read", "write", "execute", "delete", and "readlink". *

* The actions string is converted to lowercase before processing. - *

- * Be careful when granting FilePermissions. Think about the implications - * of granting read and especially write access to various files and - * directories. The {@literal "<>"} permission with write action is - * especially dangerous. This grants permission to write to the entire - * file system. One thing this effectively allows is replacement of the - * system binary, including the JVM runtime environment. - *

- * Please note: Code can always read a file from the same - * directory it's in (or a subdirectory of that directory); it does not - * need explicit permission to do so. + * + * @apiNote + * This permission cannot be used for controlling access to resources + * as the Security Manager is no longer supported. * * @see java.security.Permission * @see java.security.Permissions diff --git a/src/java.base/share/classes/java/io/ObjectInputFilter.java b/src/java.base/share/classes/java/io/ObjectInputFilter.java index 879820761c129..9a04e1f58e330 100644 --- a/src/java.base/share/classes/java/io/ObjectInputFilter.java +++ b/src/java.base/share/classes/java/io/ObjectInputFilter.java @@ -728,8 +728,6 @@ public static ObjectInputFilter getSerialFilter() { * Set the static JVM-wide filter if it has not already been configured or set. * * @param filter the deserialization filter to set as the JVM-wide filter; not null - * @throws SecurityException if there is security manager and the - * {@code SerializablePermission("serialFilter")} is not granted * @throws IllegalStateException if the filter has already been set or the initialization * of the filter from the system property {@code jdk.serialFilter} or * the security property {@code jdk.serialFilter} fails. @@ -829,8 +827,6 @@ static BinaryOperator getSerialFilterFactorySingleton() { * @throws IllegalStateException if the builtin deserialization filter factory * has already been replaced or any instance of {@link ObjectInputStream} * has been created. - * @throws SecurityException if there is security manager and the - * {@code SerializablePermission("serialFilter")} is not granted * @since 17 */ public static void setSerialFilterFactory(BinaryOperator filterFactory) { diff --git a/src/java.base/share/classes/java/io/ObjectInputStream.java b/src/java.base/share/classes/java/io/ObjectInputStream.java index 983b80d2bc673..60d8cadf6a341 100644 --- a/src/java.base/share/classes/java/io/ObjectInputStream.java +++ b/src/java.base/share/classes/java/io/ObjectInputStream.java @@ -374,17 +374,9 @@ private static class Logging { * When the filter factory {@code apply} method is invoked it may throw a runtime exception * preventing the {@code ObjectInputStream} from being constructed. * - *

If a security manager is installed, this constructor will check for - * the "enableSubclassImplementation" SerializablePermission when invoked - * directly or indirectly by the constructor of a subclass which overrides - * the ObjectInputStream.readFields or ObjectInputStream.readUnshared - * methods. - * * @param in input stream to read from * @throws StreamCorruptedException if the stream header is incorrect * @throws IOException if an I/O error occurs while reading stream header - * @throws SecurityException if untrusted subclass illegally overrides - * security-sensitive methods * @throws IllegalStateException if the initialization of {@link ObjectInputFilter.Config} * fails due to invalid serial filter or serial filter factory properties. * @throws NullPointerException if {@code in} is {@code null} @@ -419,21 +411,11 @@ public ObjectInputStream(InputStream in) throws IOException { * When the filter factory {@code apply} method is invoked it may throw a runtime exception * preventing the {@code ObjectInputStream} from being constructed. * - *

If there is a security manager installed, this method first calls the - * security manager's {@code checkPermission} method with the - * {@code SerializablePermission("enableSubclassImplementation")} - * permission to ensure it's ok to enable subclassing. - * - * @throws SecurityException if a security manager exists and its - * {@code checkPermission} method denies enabling - * subclassing. * @throws IOException if an I/O error occurs while creating this stream * @throws IllegalStateException if the initialization of {@link ObjectInputFilter.Config} * fails due to invalid serial filter or serial filter factory properties. - * @see SecurityManager#checkPermission - * @see java.io.SerializablePermission */ - protected ObjectInputStream() throws IOException, SecurityException { + protected ObjectInputStream() throws IOException { @SuppressWarnings("removal") SecurityManager sm = System.getSecurityManager(); if (sm != null) { @@ -599,12 +581,6 @@ protected Object readObjectOverride() * each object (regular or class) read to reconstruct the root object. * See {@link #setObjectInputFilter(ObjectInputFilter) setObjectInputFilter} for details. * - *

ObjectInputStream subclasses which override this method can only be - * constructed in security contexts possessing the - * "enableSubclassImplementation" SerializablePermission; any attempt to - * instantiate such a subclass without this permission will cause a - * SecurityException to be thrown. - * * @return reference to deserialized object * @throws ClassNotFoundException if class of an object to deserialize * cannot be found @@ -923,26 +899,11 @@ protected Object resolveObject(Object obj) throws IOException { * enabled, the {@link #resolveObject} method is called for every object being * deserialized. * - *

If object replacement is currently not enabled, and - * {@code enable} is true, and there is a security manager installed, - * this method first calls the security manager's - * {@code checkPermission} method with the - * {@code SerializablePermission("enableSubstitution")} permission to - * ensure that the caller is permitted to enable the stream to do replacement - * of objects read from the stream. - * * @param enable true for enabling use of {@code resolveObject} for * every object being deserialized * @return the previous setting before this method was invoked - * @throws SecurityException if a security manager exists and its - * {@code checkPermission} method denies enabling the stream - * to do replacement of objects read from the stream. - * @see SecurityManager#checkPermission - * @see java.io.SerializablePermission */ - protected boolean enableResolveObject(boolean enable) - throws SecurityException - { + protected boolean enableResolveObject(boolean enable) { if (enable == enableResolve) { return enable; } @@ -1341,8 +1302,6 @@ public final ObjectInputFilter getObjectInputFilter() { * is increased before reading an object. * * @param filter the filter, may be null - * @throws SecurityException if there is security manager and the - * {@code SerializablePermission("serialFilter")} is not granted * @throws IllegalStateException if an object has been read, * if the filter factory returns {@code null} when the * {@linkplain #getObjectInputFilter() current filter} is non-null, or diff --git a/src/java.base/share/classes/java/io/ObjectOutputStream.java b/src/java.base/share/classes/java/io/ObjectOutputStream.java index bde069a1774d1..429c91ab673b1 100644 --- a/src/java.base/share/classes/java/io/ObjectOutputStream.java +++ b/src/java.base/share/classes/java/io/ObjectOutputStream.java @@ -237,16 +237,8 @@ protected Boolean computeValue(Class type) { * ensure that constructors for receiving ObjectInputStreams will not block * when reading the header. * - *

If a security manager is installed, this constructor will check for - * the "enableSubclassImplementation" SerializablePermission when invoked - * directly or indirectly by the constructor of a subclass which overrides - * the ObjectOutputStream.putFields or ObjectOutputStream.writeUnshared - * methods. - * * @param out output stream to write to * @throws IOException if an I/O error occurs while writing stream header - * @throws SecurityException if untrusted subclass illegally overrides - * security-sensitive methods * @throws NullPointerException if {@code out} is {@code null} * @since 1.4 * @see ObjectOutputStream#ObjectOutputStream() @@ -274,19 +266,9 @@ public ObjectOutputStream(OutputStream out) throws IOException { * ObjectOutputStream to not have to allocate private data just used by * this implementation of ObjectOutputStream. * - *

If there is a security manager installed, this method first calls the - * security manager's {@code checkPermission} method with a - * {@code SerializablePermission("enableSubclassImplementation")} - * permission to ensure it's ok to enable subclassing. - * - * @throws SecurityException if a security manager exists and its - * {@code checkPermission} method denies enabling - * subclassing. * @throws IOException if an I/O error occurs while creating this stream - * @see SecurityManager#checkPermission - * @see java.io.SerializablePermission */ - protected ObjectOutputStream() throws IOException, SecurityException { + protected ObjectOutputStream() throws IOException { @SuppressWarnings("removal") SecurityManager sm = System.getSecurityManager(); if (sm != null) { @@ -414,12 +396,6 @@ protected void writeObjectOverride(Object obj) throws IOException { * writeUnshared, and not to any transitively referenced sub-objects in the * object graph to be serialized. * - *

ObjectOutputStream subclasses which override this method can only be - * constructed in security contexts possessing the - * "enableSubclassImplementation" SerializablePermission; any attempt to - * instantiate such a subclass without this permission will cause a - * SecurityException to be thrown. - * * @param obj object to write to stream * @throws NotSerializableException if an object in the graph to be * serialized does not implement the Serializable interface @@ -611,26 +587,11 @@ protected Object replaceObject(Object obj) throws IOException { * enabled, the {@link #replaceObject} method is called for every object being * serialized. * - *

If object replacement is currently not enabled, and - * {@code enable} is true, and there is a security manager installed, - * this method first calls the security manager's - * {@code checkPermission} method with the - * {@code SerializablePermission("enableSubstitution")} permission to - * ensure that the caller is permitted to enable the stream to do replacement - * of objects written to the stream. - * * @param enable true for enabling use of {@code replaceObject} for * every object being serialized * @return the previous setting before this method was invoked - * @throws SecurityException if a security manager exists and its - * {@code checkPermission} method denies enabling the stream - * to do replacement of objects written to the stream. - * @see SecurityManager#checkPermission - * @see java.io.SerializablePermission */ - protected boolean enableReplaceObject(boolean enable) - throws SecurityException - { + protected boolean enableReplaceObject(boolean enable) { if (enable == enableReplace) { return enable; } diff --git a/src/java.base/share/classes/java/io/PrintStream.java b/src/java.base/share/classes/java/io/PrintStream.java index 35e2716dbd324..3096f2356f52f 100644 --- a/src/java.base/share/classes/java/io/PrintStream.java +++ b/src/java.base/share/classes/java/io/PrintStream.java @@ -249,10 +249,6 @@ public PrintStream(OutputStream out, boolean autoFlush, Charset charset) { * created, or if some other error occurs while opening or * creating the file * - * @throws SecurityException - * If a security manager is present and {@link - * SecurityManager#checkWrite checkWrite(fileName)} denies write - * access to the file * @see Charset#defaultCharset() * * @since 1.5 @@ -284,11 +280,6 @@ public PrintStream(String fileName) throws FileNotFoundException { * created, or if some other error occurs while opening or * creating the file * - * @throws SecurityException - * If a security manager is present and {@link - * SecurityManager#checkWrite checkWrite(fileName)} denies write - * access to the file - * * @throws UnsupportedEncodingException * If the named charset is not supported * @@ -320,11 +311,6 @@ public PrintStream(String fileName, String csn) * @throws IOException * if an I/O error occurs while opening or creating the file * - * @throws SecurityException - * If a security manager is present and {@link - * SecurityManager#checkWrite checkWrite(fileName)} denies write - * access to the file - * * @since 10 */ public PrintStream(String fileName, Charset charset) throws IOException { @@ -351,10 +337,6 @@ public PrintStream(String fileName, Charset charset) throws IOException { * created, or if some other error occurs while opening or * creating the file * - * @throws SecurityException - * If a security manager is present and {@link - * SecurityManager#checkWrite checkWrite(file.getPath())} - * denies write access to the file * @see Charset#defaultCharset() * * @since 1.5 @@ -386,11 +368,6 @@ public PrintStream(File file) throws FileNotFoundException { * created, or if some other error occurs while opening or * creating the file * - * @throws SecurityException - * If a security manager is present and {@link - * SecurityManager#checkWrite checkWrite(file.getPath())} - * denies write access to the file - * * @throws UnsupportedEncodingException * If the named charset is not supported * @@ -423,11 +400,6 @@ public PrintStream(File file, String csn) * @throws IOException * if an I/O error occurs while opening or creating the file * - * @throws SecurityException - * If a security manager is present and {@link - * SecurityManager#checkWrite checkWrite(file.getPath())} - * denies write access to the file - * * @since 10 */ public PrintStream(File file, Charset charset) throws IOException { diff --git a/src/java.base/share/classes/java/io/PrintWriter.java b/src/java.base/share/classes/java/io/PrintWriter.java index 2ed9315ba6a30..55baa2e0a5701 100644 --- a/src/java.base/share/classes/java/io/PrintWriter.java +++ b/src/java.base/share/classes/java/io/PrintWriter.java @@ -195,10 +195,6 @@ public PrintWriter(OutputStream out, boolean autoFlush, Charset charset) { * created, or if some other error occurs while opening or * creating the file * - * @throws SecurityException - * If a security manager is present and {@link - * SecurityManager#checkWrite checkWrite(fileName)} denies write - * access to the file * @see Charset#defaultCharset() * * @since 1.5 @@ -247,11 +243,6 @@ private PrintWriter(Charset charset, File file) * created, or if some other error occurs while opening or * creating the file * - * @throws SecurityException - * If a security manager is present and {@link - * SecurityManager#checkWrite checkWrite(fileName)} denies write - * access to the file - * * @throws UnsupportedEncodingException * If the named charset is not supported * @@ -282,11 +273,6 @@ public PrintWriter(String fileName, String csn) * @throws IOException * if an I/O error occurs while opening or creating the file * - * @throws SecurityException - * If a security manager is present and {@link - * SecurityManager#checkWrite checkWrite(fileName)} denies write - * access to the file - * * @since 10 */ public PrintWriter(String fileName, Charset charset) throws IOException { @@ -313,10 +299,6 @@ public PrintWriter(String fileName, Charset charset) throws IOException { * created, or if some other error occurs while opening or * creating the file * - * @throws SecurityException - * If a security manager is present and {@link - * SecurityManager#checkWrite checkWrite(file.getPath())} - * denies write access to the file * @see Charset#defaultCharset() * * @since 1.5 @@ -348,11 +330,6 @@ public PrintWriter(File file) throws FileNotFoundException { * created, or if some other error occurs while opening or * creating the file * - * @throws SecurityException - * If a security manager is present and {@link - * SecurityManager#checkWrite checkWrite(file.getPath())} - * denies write access to the file - * * @throws UnsupportedEncodingException * If the named charset is not supported * @@ -383,11 +360,6 @@ public PrintWriter(File file, String csn) * @throws IOException * if an I/O error occurs while opening or creating the file * - * @throws SecurityException - * If a security manager is present and {@link - * SecurityManager#checkWrite checkWrite(file.getPath())} - * denies write access to the file - * * @since 10 */ public PrintWriter(File file, Charset charset) throws IOException { diff --git a/src/java.base/share/classes/java/io/RandomAccessFile.java b/src/java.base/share/classes/java/io/RandomAccessFile.java index cf8ae43dc2147..1487764ac4475 100644 --- a/src/java.base/share/classes/java/io/RandomAccessFile.java +++ b/src/java.base/share/classes/java/io/RandomAccessFile.java @@ -114,15 +114,6 @@ public class RandomAccessFile implements DataOutput, DataInput, Closeable { * specified for the {@code RandomAccessFile(File,String)} constructor. * - *

- * If there is a security manager, its {@code checkRead} method - * is called with the {@code pathname} argument - * as its argument to see if read access to the file is allowed. - * If the mode allows writing, the security manager's - * {@code checkWrite} method - * is also called with the {@code pathname} argument - * as its argument to see if write access to the file is allowed. - * * @param pathname the system-dependent pathname string * @param mode the access mode * @throws IllegalArgumentException if the mode argument is not equal @@ -135,13 +126,6 @@ public class RandomAccessFile implements DataOutput, DataInput, Closeable { * existing, writable regular file and a new regular file of * that pathname cannot be created, or if some other error * occurs while opening or creating the file - * @throws SecurityException if a security manager exists and its - * {@code checkRead} method denies read access to the file - * or the mode is {@code "rw"} and the security manager's - * {@code checkWrite} method denies write access to the file - * @see java.lang.SecurityException - * @see java.lang.SecurityManager#checkRead(java.lang.String) - * @see java.lang.SecurityManager#checkWrite(java.lang.String) */ public RandomAccessFile(String pathname, String mode) throws FileNotFoundException @@ -205,13 +189,6 @@ public RandomAccessFile(String pathname, String mode) * updates to both the file's content and its metadata to be written, which * generally requires at least one more low-level I/O operation. * - *

If there is a security manager, its {@code checkRead} method is - * called with the pathname of the {@code file} argument as its - * argument to see if read access to the file is allowed. If the mode - * allows writing, the security manager's {@code checkWrite} method is - * also called with the pathname of the {@code file} argument to see if - * write access to the file is allowed. - * * @param file the file object * @param mode the access mode, as described * above @@ -225,12 +202,6 @@ public RandomAccessFile(String pathname, String mode) * an existing, writable regular file and a new regular file of * that pathname cannot be created, or if some other error * occurs while opening or creating the file - * @throws SecurityException if a security manager exists and its - * {@code checkRead} method denies read access to the file - * or the mode is {@code "rw"} and the security manager's - * {@code checkWrite} method denies write access to the file - * @see java.lang.SecurityManager#checkRead(java.lang.String) - * @see java.lang.SecurityManager#checkWrite(java.lang.String) * @see java.nio.channels.FileChannel#force(boolean) */ @SuppressWarnings("this-escape") diff --git a/src/java.base/share/classes/java/io/SerializablePermission.java b/src/java.base/share/classes/java/io/SerializablePermission.java index 914b5b13dc3bd..1e617e173a755 100644 --- a/src/java.base/share/classes/java/io/SerializablePermission.java +++ b/src/java.base/share/classes/java/io/SerializablePermission.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2019, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2024, 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 @@ -36,55 +36,9 @@ * no actions list; you either have the named permission * or you don't. * - *

- * The target name is the name of the Serializable permission (see below). - * - *

- * The following table lists the standard {@code SerializablePermission} target names, - * and for each provides a description of what the permission allows - * and a discussion of the risks of granting code the permission. - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - *
Permission target name, what the permission allows, and associated risks
Permission Target NameWhat the Permission AllowsRisks of Allowing this Permission
enableSubclassImplementationSubclass implementation of ObjectOutputStream or ObjectInputStream - * to override the default serialization or deserialization, respectively, - * of objectsCode can use this to serialize or - * deserialize classes in a purposefully malfeasant manner. For example, - * during serialization, malicious code can use this to - * purposefully store confidential private field data in a way easily accessible - * to attackers. Or, during deserialization it could, for example, deserialize - * a class with all its private fields zeroed out.
enableSubstitutionSubstitution of one object for another during - * serialization or deserializationThis is dangerous because malicious code - * can replace the actual object with one which has incorrect or - * malignant data.
serialFilterSetting a filter for ObjectInputStreams.Code could remove a configured filter and remove protections - * already established.
+ * @apiNote + * This permission cannot be used for controlling access to resources + * as the Security Manager is no longer supported. * * @see java.security.BasicPermission * @see java.security.Permission @@ -92,7 +46,6 @@ * @see java.security.PermissionCollection * @see java.lang.SecurityManager * - * * @author Joe Fialli * @since 1.2 */ diff --git a/src/java.base/share/classes/java/lang/Boolean.java b/src/java.base/share/classes/java/lang/Boolean.java index 31507f60e3782..f5c643881a883 100644 --- a/src/java.base/share/classes/java/lang/Boolean.java +++ b/src/java.base/share/classes/java/lang/Boolean.java @@ -271,8 +271,6 @@ public boolean equals(Object obj) { * * @param name the system property name. * @return the {@code boolean} value of the system property. - * @throws SecurityException for the same reasons as - * {@link System#getProperty(String) System.getProperty} * @see java.lang.System#getProperty(java.lang.String) * @see java.lang.System#getProperty(java.lang.String, java.lang.String) */ diff --git a/src/java.base/share/classes/java/lang/Class.java b/src/java.base/share/classes/java/lang/Class.java index 2edf0a9169e86..bb091235646bd 100644 --- a/src/java.base/share/classes/java/lang/Class.java +++ b/src/java.base/share/classes/java/lang/Class.java @@ -530,11 +530,6 @@ private static Class forName(String className, Class caller) * by this method fails * @throws ClassNotFoundException if the class cannot be located by * the specified class loader - * @throws SecurityException - * if a security manager is present, and the {@code loader} is - * {@code null}, and the caller's class loader is not - * {@code null}, and the caller does not have the - * {@link RuntimePermission}{@code ("getClassLoader")} * * @see java.lang.Class#forName(String) * @see java.lang.ClassLoader @@ -610,8 +605,6 @@ private static native Class forName0(String name, boolean initialize, * a binary name. This method returns {@code null} on failure rather than * throwing a {@link ClassNotFoundException}, as is done by * the {@link #forName(String, boolean, ClassLoader)} method. - * The security check is a stack-based permission check if the caller - * loads a class in another module. * * @param module A module * @param name The {@linkplain ClassLoader##binary-name binary name} @@ -623,16 +616,6 @@ private static native Class forName0(String name, boolean initialize, * * @throws LinkageError if the linkage fails * - * @throws SecurityException - *

- * * @jls 12.2 Loading of Classes and Interfaces * @jls 12.3 Linking of Classes and Interfaces * @since 9 @@ -756,13 +739,6 @@ public static Class forPrimitiveName(String primitiveName) { * or if the instantiation fails for some other reason. * @throws ExceptionInInitializerError if the initialization * provoked by this method fails. - * @throws SecurityException - * If a security manager, s, is present and - * the caller's class loader is not the same as or an - * ancestor of the class loader for the current class and - * invocation of {@link SecurityManager#checkPackageAccess - * s.checkPackageAccess()} denies access to the package - * of this class. */ @SuppressWarnings("removal") @CallerSensitive @@ -1057,15 +1033,7 @@ public String getName() { * * @return the class loader that loaded the class or interface * represented by this {@code Class} object. - * @throws SecurityException - * if a security manager is present, and the caller's class loader - * is not {@code null} and is not the same as or an ancestor of the - * class loader for the class whose class loader is requested, - * and the caller does not have the - * {@link RuntimePermission}{@code ("getClassLoader")} * @see java.lang.ClassLoader - * @see SecurityManager#checkPermission - * @see java.lang.RuntimePermission */ @CallerSensitive @ForceInline // to ensure Reflection.getCallerClass optimization @@ -1541,30 +1509,10 @@ void setSigners(Object[] signers) { * @return the immediately enclosing method of the underlying class, if * that class is a local or anonymous class; otherwise {@code null}. * - * @throws SecurityException - * If a security manager, s, is present and any of the - * following conditions is met: - * - * * @since 1.5 */ @CallerSensitive - public Method getEnclosingMethod() throws SecurityException { + public Method getEnclosingMethod() { EnclosingMethodInfo enclosingInfo = getEnclosingMethodInfo(); if (enclosingInfo == null) @@ -1697,30 +1645,11 @@ private static Class toClass(Type o) { * * @return the immediately enclosing constructor of the underlying class, if * that class is a local or anonymous class; otherwise {@code null}. - * @throws SecurityException - * If a security manager, s, is present and any of the - * following conditions is met: - * - * + * * @since 1.5 */ @CallerSensitive - public Constructor getEnclosingConstructor() throws SecurityException { + public Constructor getEnclosingConstructor() { EnclosingMethodInfo enclosingInfo = getEnclosingMethodInfo(); if (enclosingInfo == null) @@ -1777,16 +1706,10 @@ public Constructor getEnclosingConstructor() throws SecurityException { * type, or void, then this method returns null. * * @return the declaring class for this class - * @throws SecurityException - * If a security manager, s, is present and the caller's - * class loader is not the same as or an ancestor of the class - * loader for the declaring class and invocation of {@link - * SecurityManager#checkPackageAccess s.checkPackageAccess()} - * denies access to the package of the declaring class * @since 1.1 */ @CallerSensitive - public Class getDeclaringClass() throws SecurityException { + public Class getDeclaringClass() { final Class candidate = getDeclaringClass0(); if (candidate != null) { @@ -1808,16 +1731,10 @@ public Class getDeclaringClass() throws SecurityException { * class. If the underlying class is a top level class this * method returns {@code null}. * @return the immediately enclosing class of the underlying class - * @throws SecurityException - * If a security manager, s, is present and the caller's - * class loader is not the same as or an ancestor of the class - * loader for the enclosing class and invocation of {@link - * SecurityManager#checkPackageAccess s.checkPackageAccess()} - * denies access to the package of the enclosing class * @since 1.5 */ @CallerSensitive - public Class getEnclosingClass() throws SecurityException { + public Class getEnclosingClass() { // There are five kinds of classes (or interfaces): // a) Top level classes // b) Nested classes (static member classes) @@ -2072,14 +1989,6 @@ private boolean hasEnclosingMethodInfo() { * * @return the array of {@code Class} objects representing the public * members of this class - * @throws SecurityException - * If a security manager, s, is present and - * the caller's class loader is not the same as or an - * ancestor of the class loader for the current class and - * invocation of {@link SecurityManager#checkPackageAccess - * s.checkPackageAccess()} denies access to the package - * of this class. - * * @since 1.1 */ @SuppressWarnings("removal") @@ -2140,20 +2049,13 @@ public Class[] run() { * * @return the array of {@code Field} objects representing the * public fields - * @throws SecurityException - * If a security manager, s, is present and - * the caller's class loader is not the same as or an - * ancestor of the class loader for the current class and - * invocation of {@link SecurityManager#checkPackageAccess - * s.checkPackageAccess()} denies access to the package - * of this class. * * @since 1.1 * @jls 8.2 Class Members * @jls 8.3 Field Declarations */ @CallerSensitive - public Field[] getFields() throws SecurityException { + public Field[] getFields() { @SuppressWarnings("removal") SecurityManager sm = System.getSecurityManager(); if (sm != null) { @@ -2231,20 +2133,13 @@ public Field[] getFields() throws SecurityException { * * @return the array of {@code Method} objects representing the * public methods of this class - * @throws SecurityException - * If a security manager, s, is present and - * the caller's class loader is not the same as or an - * ancestor of the class loader for the current class and - * invocation of {@link SecurityManager#checkPackageAccess - * s.checkPackageAccess()} denies access to the package - * of this class. * * @jls 8.2 Class Members * @jls 8.4 Method Declarations * @since 1.1 */ @CallerSensitive - public Method[] getMethods() throws SecurityException { + public Method[] getMethods() { @SuppressWarnings("removal") SecurityManager sm = System.getSecurityManager(); if (sm != null) { @@ -2274,19 +2169,12 @@ public Method[] getMethods() throws SecurityException { * * @return the array of {@code Constructor} objects representing the * public constructors of this class - * @throws SecurityException - * If a security manager, s, is present and - * the caller's class loader is not the same as or an - * ancestor of the class loader for the current class and - * invocation of {@link SecurityManager#checkPackageAccess - * s.checkPackageAccess()} denies access to the package - * of this class. * * @see #getDeclaredConstructors() * @since 1.1 */ @CallerSensitive - public Constructor[] getConstructors() throws SecurityException { + public Constructor[] getConstructors() { @SuppressWarnings("removal") SecurityManager sm = System.getSecurityManager(); if (sm != null) { @@ -2326,21 +2214,13 @@ public Constructor[] getConstructors() throws SecurityException { * @throws NoSuchFieldException if a field with the specified name is * not found. * @throws NullPointerException if {@code name} is {@code null} - * @throws SecurityException - * If a security manager, s, is present and - * the caller's class loader is not the same as or an - * ancestor of the class loader for the current class and - * invocation of {@link SecurityManager#checkPackageAccess - * s.checkPackageAccess()} denies access to the package - * of this class. * * @since 1.1 * @jls 8.2 Class Members * @jls 8.3 Field Declarations */ @CallerSensitive - public Field getField(String name) - throws NoSuchFieldException, SecurityException { + public Field getField(String name) throws NoSuchFieldException { Objects.requireNonNull(name); @SuppressWarnings("removal") SecurityManager sm = System.getSecurityManager(); @@ -2437,13 +2317,6 @@ public Field getField(String name) * or if the name is {@value ConstantDescs#INIT_NAME} or * {@value ConstantDescs#CLASS_INIT_NAME}. * @throws NullPointerException if {@code name} is {@code null} - * @throws SecurityException - * If a security manager, s, is present and - * the caller's class loader is not the same as or an - * ancestor of the class loader for the current class and - * invocation of {@link SecurityManager#checkPackageAccess - * s.checkPackageAccess()} denies access to the package - * of this class. * * @jls 8.2 Class Members * @jls 8.4 Method Declarations @@ -2451,7 +2324,7 @@ public Field getField(String name) */ @CallerSensitive public Method getMethod(String name, Class... parameterTypes) - throws NoSuchMethodException, SecurityException { + throws NoSuchMethodException { Objects.requireNonNull(name); @SuppressWarnings("removal") SecurityManager sm = System.getSecurityManager(); @@ -2486,21 +2359,13 @@ public Method getMethod(String name, Class... parameterTypes) * @throws NoSuchMethodException if a matching constructor is not found, * including when this {@code Class} object represents * an interface, a primitive type, an array class, or void. - * @throws SecurityException - * If a security manager, s, is present and - * the caller's class loader is not the same as or an - * ancestor of the class loader for the current class and - * invocation of {@link SecurityManager#checkPackageAccess - * s.checkPackageAccess()} denies access to the package - * of this class. - * - * @see #getDeclaredConstructor(Class[]) + * + * @see #getDeclaredConstructor(Class[]) * @since 1.1 */ @CallerSensitive public Constructor getConstructor(Class... parameterTypes) - throws NoSuchMethodException, SecurityException - { + throws NoSuchMethodException { @SuppressWarnings("removal") SecurityManager sm = System.getSecurityManager(); if (sm != null) { @@ -2523,32 +2388,12 @@ public Constructor getConstructor(Class... parameterTypes) * * @return the array of {@code Class} objects representing all the * declared members of this class - * @throws SecurityException - * If a security manager, s, is present and any of the - * following conditions is met: - * - *
    - * - *
  • the caller's class loader is not the same as the - * class loader of this class and invocation of - * {@link SecurityManager#checkPermission - * s.checkPermission} method with - * {@code RuntimePermission("accessDeclaredMembers")} - * denies access to the declared classes within this class - * - *
  • the caller's class loader is not the same as or an - * ancestor of the class loader for the current class and - * invocation of {@link SecurityManager#checkPackageAccess - * s.checkPackageAccess()} denies access to the package - * of this class - * - *
* * @since 1.1 * @jls 8.5 Member Class and Interface Declarations */ @CallerSensitive - public Class[] getDeclaredClasses() throws SecurityException { + public Class[] getDeclaredClasses() { @SuppressWarnings("removal") SecurityManager sm = System.getSecurityManager(); if (sm != null) { @@ -2575,33 +2420,13 @@ public Class[] getDeclaredClasses() throws SecurityException { * * @return the array of {@code Field} objects representing all the * declared fields of this class - * @throws SecurityException - * If a security manager, s, is present and any of the - * following conditions is met: - * - *
    - * - *
  • the caller's class loader is not the same as the - * class loader of this class and invocation of - * {@link SecurityManager#checkPermission - * s.checkPermission} method with - * {@code RuntimePermission("accessDeclaredMembers")} - * denies access to the declared fields within this class - * - *
  • the caller's class loader is not the same as or an - * ancestor of the class loader for the current class and - * invocation of {@link SecurityManager#checkPackageAccess - * s.checkPackageAccess()} denies access to the package - * of this class - * - *
* * @since 1.1 * @jls 8.2 Class Members * @jls 8.3 Field Declarations */ @CallerSensitive - public Field[] getDeclaredFields() throws SecurityException { + public Field[] getDeclaredFields() { @SuppressWarnings("removal") SecurityManager sm = System.getSecurityManager(); if (sm != null) { @@ -2638,26 +2463,6 @@ public Field[] getDeclaredFields() throws SecurityException { * @return An array of {@code RecordComponent} objects representing all the * record components of this record class, or {@code null} if this * class is not a record class - * @throws SecurityException - * If a security manager, s, is present and any of the - * following conditions is met: - * - *
    - * - *
  • the caller's class loader is not the same as the - * class loader of this class and invocation of - * {@link SecurityManager#checkPermission - * s.checkPermission} method with - * {@code RuntimePermission("accessDeclaredMembers")} - * denies access to the declared methods within this class - * - *
  • the caller's class loader is not the same as or an - * ancestor of the class loader for the current class and - * invocation of {@link SecurityManager#checkPackageAccess - * s.checkPackageAccess()} denies access to the package - * of this class - * - *
* * @jls 8.10 Record Classes * @since 16 @@ -2706,26 +2511,6 @@ public RecordComponent[] getRecordComponents() { * * @return the array of {@code Method} objects representing all the * declared methods of this class - * @throws SecurityException - * If a security manager, s, is present and any of the - * following conditions is met: - * - *
    - * - *
  • the caller's class loader is not the same as the - * class loader of this class and invocation of - * {@link SecurityManager#checkPermission - * s.checkPermission} method with - * {@code RuntimePermission("accessDeclaredMembers")} - * denies access to the declared methods within this class - * - *
  • the caller's class loader is not the same as or an - * ancestor of the class loader for the current class and - * invocation of {@link SecurityManager#checkPackageAccess - * s.checkPackageAccess()} denies access to the package - * of this class - * - *
* * @jls 8.2 Class Members * @jls 8.4 Method Declarations @@ -2735,7 +2520,7 @@ public RecordComponent[] getRecordComponents() { * @since 1.1 */ @CallerSensitive - public Method[] getDeclaredMethods() throws SecurityException { + public Method[] getDeclaredMethods() { @SuppressWarnings("removal") SecurityManager sm = System.getSecurityManager(); if (sm != null) { @@ -2760,33 +2545,13 @@ public Method[] getDeclaredMethods() throws SecurityException { * * @return the array of {@code Constructor} objects representing all the * declared constructors of this class - * @throws SecurityException - * If a security manager, s, is present and any of the - * following conditions is met: - * - *
    - * - *
  • the caller's class loader is not the same as the - * class loader of this class and invocation of - * {@link SecurityManager#checkPermission - * s.checkPermission} method with - * {@code RuntimePermission("accessDeclaredMembers")} - * denies access to the declared constructors within this class - * - *
  • the caller's class loader is not the same as or an - * ancestor of the class loader for the current class and - * invocation of {@link SecurityManager#checkPackageAccess - * s.checkPackageAccess()} denies access to the package - * of this class - * - *
* * @since 1.1 * @see #getConstructors() * @jls 8.8 Constructor Declarations */ @CallerSensitive - public Constructor[] getDeclaredConstructors() throws SecurityException { + public Constructor[] getDeclaredConstructors() { @SuppressWarnings("removal") SecurityManager sm = System.getSecurityManager(); if (sm != null) { @@ -2811,34 +2576,13 @@ public Constructor[] getDeclaredConstructors() throws SecurityException { * @throws NoSuchFieldException if a field with the specified name is * not found. * @throws NullPointerException if {@code name} is {@code null} - * @throws SecurityException - * If a security manager, s, is present and any of the - * following conditions is met: - * - *
    - * - *
  • the caller's class loader is not the same as the - * class loader of this class and invocation of - * {@link SecurityManager#checkPermission - * s.checkPermission} method with - * {@code RuntimePermission("accessDeclaredMembers")} - * denies access to the declared field - * - *
  • the caller's class loader is not the same as or an - * ancestor of the class loader for the current class and - * invocation of {@link SecurityManager#checkPackageAccess - * s.checkPackageAccess()} denies access to the package - * of this class - * - *
* * @since 1.1 * @jls 8.2 Class Members * @jls 8.3 Field Declarations */ @CallerSensitive - public Field getDeclaredField(String name) - throws NoSuchFieldException, SecurityException { + public Field getDeclaredField(String name) throws NoSuchFieldException { Objects.requireNonNull(name); @SuppressWarnings("removal") SecurityManager sm = System.getSecurityManager(); @@ -2877,26 +2621,6 @@ public Field getDeclaredField(String name) * matching the specified name and parameters * @throws NoSuchMethodException if a matching method is not found. * @throws NullPointerException if {@code name} is {@code null} - * @throws SecurityException - * If a security manager, s, is present and any of the - * following conditions is met: - * - *
    - * - *
  • the caller's class loader is not the same as the - * class loader of this class and invocation of - * {@link SecurityManager#checkPermission - * s.checkPermission} method with - * {@code RuntimePermission("accessDeclaredMembers")} - * denies access to the declared method - * - *
  • the caller's class loader is not the same as or an - * ancestor of the class loader for the current class and - * invocation of {@link SecurityManager#checkPackageAccess - * s.checkPackageAccess()} denies access to the package - * of this class - * - *
* * @jls 8.2 Class Members * @jls 8.4 Method Declarations @@ -2904,7 +2628,7 @@ public Field getDeclaredField(String name) */ @CallerSensitive public Method getDeclaredMethod(String name, Class... parameterTypes) - throws NoSuchMethodException, SecurityException { + throws NoSuchMethodException { Objects.requireNonNull(name); @SuppressWarnings("removal") SecurityManager sm = System.getSecurityManager(); @@ -2975,34 +2699,13 @@ Method findMethod(boolean publicOnly, String name, Class... parameterTypes) { * @throws NoSuchMethodException if a matching constructor is not found, * including when this {@code Class} object represents * an interface, a primitive type, an array class, or void. - * @throws SecurityException - * If a security manager, s, is present and any of the - * following conditions is met: - * - *
    - * - *
  • the caller's class loader is not the same as the - * class loader of this class and invocation of - * {@link SecurityManager#checkPermission - * s.checkPermission} method with - * {@code RuntimePermission("accessDeclaredMembers")} - * denies access to the declared constructor - * - *
  • the caller's class loader is not the same as or an - * ancestor of the class loader for the current class and - * invocation of {@link SecurityManager#checkPackageAccess - * s.checkPackageAccess()} denies access to the package - * of this class * - *
- * - * @see #getConstructor(Class[]) + * @see #getConstructor(Class[]) * @since 1.1 */ @CallerSensitive public Constructor getDeclaredConstructor(Class... parameterTypes) - throws NoSuchMethodException, SecurityException - { + throws NoSuchMethodException { @SuppressWarnings("removal") SecurityManager sm = System.getSecurityManager(); if (sm != null) { @@ -3058,10 +2761,9 @@ public Constructor getDeclaredConstructor(Class... parameterTypes) * * @param name name of the desired resource * @return A {@link java.io.InputStream} object; {@code null} if no - * resource with this name is found, the resource is in a package + * resource with this name is found, or the resource is in a package * that is not {@linkplain Module#isOpen(String, Module) open} to at - * least the caller module, or access to the resource is denied - * by the security manager. + * least the caller module. * @throws NullPointerException If {@code name} is {@code null} * * @see Module#getResourceAsStream(String) @@ -3154,11 +2856,10 @@ public InputStream getResourceAsStream(String name) { * * @param name name of the desired resource * @return A {@link java.net.URL} object; {@code null} if no resource with - * this name is found, the resource cannot be located by a URL, the + * this name is found, the resource cannot be located by a URL, or the * resource is in a package that is not * {@linkplain Module#isOpen(String, Module) open} to at least the caller - * module, or access to the resource is denied by the security - * manager. + * module. * @throws NullPointerException If {@code name} is {@code null} * @since 1.1 */ @@ -3224,23 +2925,11 @@ private boolean isOpenToCaller(String name, Class caller) { } /** - * Returns the {@code ProtectionDomain} of this class. If there is a - * security manager installed, this method first calls the security - * manager's {@code checkPermission} method with a - * {@code RuntimePermission("getProtectionDomain")} permission to - * ensure it's ok to get the - * {@code ProtectionDomain}. + * Returns the {@code ProtectionDomain} of this class. * * @return the ProtectionDomain of this class * - * @throws SecurityException - * if a security manager exists and its - * {@code checkPermission} method doesn't allow - * getting the ProtectionDomain. - * * @see java.security.ProtectionDomain - * @see SecurityManager#checkPermission - * @see java.lang.RuntimePermission * @since 1.2 */ public ProtectionDomain getProtectionDomain() { @@ -4466,13 +4155,6 @@ public AnnotatedType[] getAnnotatedInterfaces() { * * @return the nest host of this class or interface * - * @throws SecurityException - * If the returned class is not the current class, and - * if a security manager, s, is present and the caller's - * class loader is not the same as or an ancestor of the class - * loader for the returned class and invocation of {@link - * SecurityManager#checkPackageAccess s.checkPackageAccess()} - * denies access to the package of the returned class * @since 11 * @jvms 4.7.28 The {@code NestHost} Attribute * @jvms 4.7.29 The {@code NestMembers} Attribute @@ -4557,14 +4239,6 @@ public boolean isNestmateOf(Class c) { * @return an array of all classes and interfaces in the same nest as * this class or interface * - * @throws SecurityException - * If any returned class is not the current class, and - * if a security manager, s, is present and the caller's - * class loader is not the same as or an ancestor of the class - * loader for that returned class and invocation of {@link - * SecurityManager#checkPackageAccess s.checkPackageAccess()} - * denies access to the package of that returned class - * * @since 11 * @see #getNestHost() * @jvms 4.7.28 The {@code NestHost} Attribute @@ -4751,15 +4425,8 @@ public Optional describeConstable() { * cannot be obtained, it is silently ignored, and not included in the result * array. * - * @return an array of {@code Class} objects of the permitted subclasses of this class or interface, - * or {@code null} if this class or interface is not sealed. - * - * @throws SecurityException - * If a security manager, s, is present and the caller's - * class loader is not the same as or an ancestor of the class - * loader for that returned class and invocation of {@link - * SecurityManager#checkPackageAccess s.checkPackageAccess()} - * denies access to the package of any class in the returned array. + * @return an array of {@code Class} objects of the permitted subclasses of this class + * or interface, or {@code null} if this class or interface is not sealed. * * @jls 8.1 Class Declarations * @jls 9.1 Interface Declarations diff --git a/src/java.base/share/classes/java/lang/ClassLoader.java b/src/java.base/share/classes/java/lang/ClassLoader.java index fafa8895ee667..85fc315c76715 100644 --- a/src/java.base/share/classes/java/lang/ClassLoader.java +++ b/src/java.base/share/classes/java/lang/ClassLoader.java @@ -33,10 +33,7 @@ import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; import java.net.URL; -import java.security.AccessController; -import java.security.AccessControlContext; import java.security.CodeSource; -import java.security.PrivilegedAction; import java.security.ProtectionDomain; import java.security.cert.Certificate; import java.util.ArrayList; @@ -67,7 +64,6 @@ import jdk.internal.reflect.CallerSensitiveAdapter; import jdk.internal.reflect.Reflection; import jdk.internal.util.StaticProperty; -import sun.reflect.misc.ReflectUtil; import sun.security.util.SecurityConstants; /** @@ -93,9 +89,6 @@ * extend the manner in which the Java virtual machine dynamically loads * classes. * - *

Class loaders may typically be used by security managers to indicate - * security domains. - * *

In addition to loading classes, a class loader is also responsible for * locating resources. A resource is some data (a "{@code .class}" file, * configuration data, or an image for example) that is identified with an @@ -424,11 +417,6 @@ String nameAndId() { * * @throws IllegalArgumentException if the given name is empty. * - * @throws SecurityException - * If a security manager exists and its - * {@link SecurityManager#checkCreateClassLoader()} - * method doesn't allow creation of a new class loader. - * * @since 9 */ @SuppressWarnings("this-escape") @@ -440,10 +428,6 @@ protected ClassLoader(String name, ClassLoader parent) { * Creates a new class loader using the specified parent class loader for * delegation. * - *

If there is a security manager, its {@link - * SecurityManager#checkCreateClassLoader() checkCreateClassLoader} method - * is invoked. This may result in a security exception.

- * * @apiNote If the parent is specified as {@code null} (for the * bootstrap class loader) then there is no guarantee that all platform * classes are visible. @@ -451,11 +435,6 @@ protected ClassLoader(String name, ClassLoader parent) { * @param parent * The parent class loader * - * @throws SecurityException - * If a security manager exists and its - * {@code checkCreateClassLoader} method doesn't allow creation - * of a new class loader. - * * @since 1.2 */ @SuppressWarnings("this-escape") @@ -467,16 +446,6 @@ protected ClassLoader(ClassLoader parent) { * Creates a new class loader using the {@code ClassLoader} returned by * the method {@link #getSystemClassLoader() * getSystemClassLoader()} as the parent class loader. - * - *

If there is a security manager, its {@link - * SecurityManager#checkCreateClassLoader() - * checkCreateClassLoader} method is invoked. This may result in - * a security exception.

- * - * @throws SecurityException - * If a security manager exists and its - * {@code checkCreateClassLoader} method doesn't allow creation - * of a new class loader. */ @SuppressWarnings("this-escape") protected ClassLoader() { @@ -688,30 +657,6 @@ protected Object getClassLoadingLock(String className) { return lock; } - // Invoked by the VM after loading class with this loader. - @SuppressWarnings("removal") - private void checkPackageAccess(Class cls, ProtectionDomain pd) { - final SecurityManager sm = System.getSecurityManager(); - if (sm != null) { - if (ReflectUtil.isNonPublicProxyClass(cls)) { - for (Class intf: cls.getInterfaces()) { - checkPackageAccess(intf, pd); - } - return; - } - - final String packageName = cls.getPackageName(); - if (!packageName.isEmpty()) { - AccessController.doPrivileged(new PrivilegedAction<>() { - public Void run() { - sm.checkPackageAccess(packageName); - return null; - } - }, new AccessControlContext(new ProtectionDomain[] {pd})); - } - } - } - /** * Finds the class with the specified binary name. * This method should be overridden by class loader implementations that @@ -823,12 +768,10 @@ protected final Class defineClass(byte[] b, int off, int len) * Before the {@code Class} can be used it must be resolved. * *

This method assigns a default {@link java.security.ProtectionDomain - * ProtectionDomain} to the newly defined class. The - * {@code ProtectionDomain} is effectively granted the same set of - * permissions returned when {@link - * java.security.Policy#getPermissions(java.security.CodeSource) - * Policy.getPolicy().getPermissions(new CodeSource(null, null))} - * is invoked. The default protection domain is created on the first invocation + * ProtectionDomain} to the newly defined class. The + * {@code getPermissions} method of the {@code ProtectionDomain} always + * returns {@code null}. + * The default protection domain is created on the first invocation * of {@link #defineClass(String, byte[], int, int) defineClass}, * and re-used on subsequent invocations. * @@ -1342,8 +1285,7 @@ protected final void setSigners(Class c, Object[] signers) { * The resource name * * @return A URL to the resource; {@code null} if the resource could not be - * found, a URL could not be constructed to locate the resource, - * access to the resource is denied by the security manager, or + * found, a URL could not be constructed to locate the resource, or * there isn't a module of the given name defined to the class * loader. * @@ -1395,9 +1337,8 @@ protected URL findResource(String moduleName, String name) throws IOException { * * @return {@code URL} object for reading the resource; {@code null} if * the resource could not be found, a {@code URL} could not be - * constructed to locate the resource, the resource is in a package - * that is not opened unconditionally, or access to the resource is - * denied by the security manager. + * constructed to locate the resource, or the resource is in a package + * that is not opened unconditionally. * * @throws NullPointerException If {@code name} is {@code null} * @@ -1457,9 +1398,8 @@ public URL getResource(String name) { * @return An enumeration of {@link java.net.URL URL} objects for the * resource. If no resources could be found, the enumeration will * be empty. Resources for which a {@code URL} cannot be - * constructed, are in a package that is not opened - * unconditionally, or access to the resource is denied by the - * security manager, are not returned in the enumeration. + * constructed, or are in a package that is not opened + * unconditionally, are not returned in the enumeration. * * @throws IOException * If I/O errors occur @@ -1518,9 +1458,8 @@ public Enumeration getResources(String name) throws IOException { * * @return A stream of resource {@link java.net.URL URL} objects. If no * resources could be found, the stream will be empty. Resources - * for which a {@code URL} cannot be constructed, are in a package - * that is not opened unconditionally, or access to the resource - * is denied by the security manager, will not be in the stream. + * for which a {@code URL} cannot be constructed, or are in a package + * that is not opened unconditionally, will not be in the stream. * * @throws NullPointerException If {@code name} is {@code null} * @@ -1558,9 +1497,8 @@ public Stream resources(String name) { * * @return {@code URL} object for reading the resource; {@code null} if * the resource could not be found, a {@code URL} could not be - * constructed to locate the resource, the resource is in a package - * that is not opened unconditionally, or access to the resource is - * denied by the security manager. + * constructed to locate the resource, or the resource is in a package + * that is not opened unconditionally. * * @since 1.2 */ @@ -1589,8 +1527,7 @@ protected URL findResource(String name) { * @return An enumeration of {@link java.net.URL URL} objects for * the resource. If no resources could be found, the enumeration * will be empty. Resources for which a {@code URL} cannot be - * constructed, are in a package that is not opened unconditionally, - * or access to the resource is denied by the security manager, + * constructed, or are in a package that is not opened unconditionally, * are not returned in the enumeration. * * @throws IOException @@ -1676,9 +1613,8 @@ public final boolean isRegisteredAsParallelCapable() { * * @return A {@link java.net.URL URL} to the resource; {@code * null} if the resource could not be found, a URL could not be - * constructed to locate the resource, the resource is in a package - * that is not opened unconditionally or access to the resource is - * denied by the security manager. + * constructed to locate the resource, or the resource is in a package + * that is not opened unconditionally. * * @since 1.1 */ @@ -1708,8 +1644,7 @@ public static URL getSystemResource(String name) { * @return An enumeration of {@link java.net.URL URL} objects for * the resource. If no resources could be found, the enumeration * will be empty. Resources for which a {@code URL} cannot be - * constructed, are in a package that is not opened unconditionally, - * or access to the resource is denied by the security manager, + * constructed, or are in a package that is not opened unconditionally, * are not returned in the enumeration. * * @throws IOException @@ -1740,9 +1675,8 @@ public static Enumeration getSystemResources(String name) * The resource name * * @return An input stream for reading the resource; {@code null} if the - * resource could not be found, the resource is in a package that - * is not opened unconditionally, or access to the resource is - * denied by the security manager. + * resource could not be found, or the resource is in a package that + * is not opened unconditionally. * * @throws NullPointerException If {@code name} is {@code null} * @@ -1774,9 +1708,8 @@ public InputStream getResourceAsStream(String name) { * The resource name * * @return An input stream for reading the resource; {@code null} if the - * resource could not be found, the resource is in a package that - * is not opened unconditionally, or access to the resource is - * denied by the security manager. + * resource could not be found, or the resource is in a package that + * is not opened unconditionally. * * @since 1.1 */ @@ -1800,12 +1733,6 @@ public static InputStream getSystemResourceAsStream(String name) { * * @return The parent {@code ClassLoader} * - * @throws SecurityException - * If a security manager is present, and the caller's class loader - * is not {@code null} and is not an ancestor of this class loader, - * and the caller does not have the - * {@link RuntimePermission}{@code ("getClassLoader")} - * * @since 1.2 */ @CallerSensitive @@ -1845,13 +1772,6 @@ public final Module getUnnamedModule() { * * @return The platform {@code ClassLoader}. * - * @throws SecurityException - * If a security manager is present, and the caller's class loader is - * not {@code null}, and the caller's class loader is not the same - * as or an ancestor of the platform class loader, - * and the caller does not have the - * {@link RuntimePermission}{@code ("getClassLoader")} - * * @since 9 */ @CallerSensitive @@ -1920,12 +1840,6 @@ public static ClassLoader getPlatformClassLoader() { * * @return The system {@code ClassLoader} * - * @throws SecurityException - * If a security manager is present, and the caller's class loader - * is not {@code null} and is not the same as or an ancestor of the - * system class loader, and the caller does not have the - * {@link RuntimePermission}{@code ("getClassLoader")} - * * @throws IllegalStateException * If invoked recursively during the construction of the class * loader specified by the "{@code java.system.class.loader}" diff --git a/src/java.base/share/classes/java/lang/Integer.java b/src/java.base/share/classes/java/lang/Integer.java index e666e977c61a5..8bf573733f2ce 100644 --- a/src/java.base/share/classes/java/lang/Integer.java +++ b/src/java.base/share/classes/java/lang/Integer.java @@ -1187,8 +1187,6 @@ public boolean equals(Object obj) { * * @param nm property name. * @return the {@code Integer} value of the property. - * @throws SecurityException for the same reasons as - * {@link System#getProperty(String) System.getProperty} * @see java.lang.System#getProperty(java.lang.String) * @see java.lang.System#getProperty(java.lang.String, java.lang.String) */ @@ -1233,8 +1231,6 @@ public static Integer getInteger(String nm) { * @param nm property name. * @param val default value. * @return the {@code Integer} value of the property. - * @throws SecurityException for the same reasons as - * {@link System#getProperty(String) System.getProperty} * @see java.lang.System#getProperty(java.lang.String) * @see java.lang.System#getProperty(java.lang.String, java.lang.String) */ @@ -1275,8 +1271,6 @@ public static Integer getInteger(String nm, int val) { * @param nm property name. * @param val default value. * @return the {@code Integer} value of the property. - * @throws SecurityException for the same reasons as - * {@link System#getProperty(String) System.getProperty} * @see System#getProperty(java.lang.String) * @see System#getProperty(java.lang.String, java.lang.String) */ diff --git a/src/java.base/share/classes/java/lang/Long.java b/src/java.base/share/classes/java/lang/Long.java index 8c083b3ec8431..e67b751470e48 100644 --- a/src/java.base/share/classes/java/lang/Long.java +++ b/src/java.base/share/classes/java/lang/Long.java @@ -1276,8 +1276,6 @@ public boolean equals(Object obj) { * * @param nm property name. * @return the {@code Long} value of the property. - * @throws SecurityException for the same reasons as - * {@link System#getProperty(String) System.getProperty} * @see java.lang.System#getProperty(java.lang.String) * @see java.lang.System#getProperty(java.lang.String, java.lang.String) */ @@ -1321,8 +1319,6 @@ public static Long getLong(String nm) { * @param nm property name. * @param val default value. * @return the {@code Long} value of the property. - * @throws SecurityException for the same reasons as - * {@link System#getProperty(String) System.getProperty} * @see java.lang.System#getProperty(java.lang.String) * @see java.lang.System#getProperty(java.lang.String, java.lang.String) */ @@ -1370,8 +1366,6 @@ public static Long getLong(String nm, long val) { * @param nm property name. * @param val default value. * @return the {@code Long} value of the property. - * @throws SecurityException for the same reasons as - * {@link System#getProperty(String) System.getProperty} * @see System#getProperty(java.lang.String) * @see System#getProperty(java.lang.String, java.lang.String) */ diff --git a/src/java.base/share/classes/java/lang/Module.java b/src/java.base/share/classes/java/lang/Module.java index 4d4593b31974f..a90fbc992602b 100644 --- a/src/java.base/share/classes/java/lang/Module.java +++ b/src/java.base/share/classes/java/lang/Module.java @@ -195,15 +195,7 @@ public String getName() { /** * Returns the {@code ClassLoader} for this module. * - *

If there is a security manager then its {@code checkPermission} - * method if first called with a {@code RuntimePermission("getClassLoader")} - * permission to check that the caller is allowed to get access to the - * class loader.

- * * @return The class loader for this module - * - * @throws SecurityException - * If denied by the security manager */ public ClassLoader getClassLoader() { @SuppressWarnings("removal") @@ -1689,9 +1681,8 @@ protected Class loadClass(String cn, boolean resolve) * with the name "{@code META-INF/MANIFEST.MF}" is never encapsulated * because "{@code META-INF}" is not a legal package name.

* - *

This method returns {@code null} if the resource is not in this - * module, the resource is encapsulated and cannot be located by the caller, - * or access to the resource is denied by the security manager.

+ *

This method returns {@code null} if the resource is not in this module + * or the resource is encapsulated and cannot be located by the caller.

* * @param name * The resource name diff --git a/src/java.base/share/classes/java/lang/ModuleLayer.java b/src/java.base/share/classes/java/lang/ModuleLayer.java index 80d392470cb33..4ee2b02414dee 100644 --- a/src/java.base/share/classes/java/lang/ModuleLayer.java +++ b/src/java.base/share/classes/java/lang/ModuleLayer.java @@ -359,10 +359,6 @@ public Controller enableNativeAccess(Module target) { * @throws LayerInstantiationException * If the layer cannot be created for any of the reasons specified * by the static {@code defineModulesWithOneLoader} method - * @throws SecurityException - * If {@code RuntimePermission("createClassLoader")} or - * {@code RuntimePermission("getClassLoader")} is denied by - * the security manager * * @see #findLoader */ @@ -401,10 +397,6 @@ public ModuleLayer defineModulesWithOneLoader(Configuration cf, * @throws LayerInstantiationException * If the layer cannot be created for any of the reasons specified * by the static {@code defineModulesWithManyLoaders} method - * @throws SecurityException - * If {@code RuntimePermission("createClassLoader")} or - * {@code RuntimePermission("getClassLoader")} is denied by - * the security manager * * @see #findLoader */ @@ -440,9 +432,6 @@ public ModuleLayer defineModulesWithManyLoaders(Configuration cf, * @throws LayerInstantiationException * If the layer cannot be created for any of the reasons specified * by the static {@code defineModules} method - * @throws SecurityException - * If {@code RuntimePermission("getClassLoader")} is denied by - * the security manager */ public ModuleLayer defineModules(Configuration cf, Function clf) { @@ -490,10 +479,6 @@ public ModuleLayer defineModules(Configuration cf, * a module named "{@code java.base}", or a module contains a package named * "{@code java}" or a package with a name starting with "{@code java.}".

* - *

If there is a security manager then the class loader created by - * this method will load classes and resources with privileges that are - * restricted by the calling context of this method.

- * * @param cf * The configuration for the layer * @param parentLayers @@ -510,10 +495,6 @@ public ModuleLayer defineModules(Configuration cf, * @throws LayerInstantiationException * If all modules cannot be defined to the same class loader for any * of the reasons listed above - * @throws SecurityException - * If {@code RuntimePermission("createClassLoader")} or - * {@code RuntimePermission("getClassLoader")} is denied by - * the security manager * * @see #findLoader */ @@ -563,10 +544,6 @@ public static Controller defineModulesWithOneLoader(Configuration cf, * methods) in the module defined to the class loader before searching * the parent class loader.

* - *

If there is a security manager then the class loaders created by - * this method will load classes and resources with privileges that are - * restricted by the calling context of this method.

- * * @param cf * The configuration for the layer * @param parentLayers @@ -586,11 +563,6 @@ public static Controller defineModulesWithOneLoader(Configuration cf, * named "{@code java}" or a package with a name starting with * "{@code java.}" * - * @throws SecurityException - * If {@code RuntimePermission("createClassLoader")} or - * {@code RuntimePermission("getClassLoader")} is denied by - * the security manager - * * @see #findLoader */ public static Controller defineModulesWithManyLoaders(Configuration cf, @@ -673,9 +645,6 @@ public static Controller defineModulesWithManyLoaders(Configuration cf, * configuration of the parent layers, including order * @throws LayerInstantiationException * If creating the layer fails for any of the reasons listed above - * @throws SecurityException - * If {@code RuntimePermission("getClassLoader")} is denied by - * the security manager */ public static Controller defineModules(Configuration cf, List parentLayers, @@ -906,11 +875,6 @@ boolean addEnableNativeAccess(String name) { * parent} layers are searched in the manner specified by {@link * #findModule(String) findModule}. * - *

If there is a security manager then its {@code checkPermission} - * method is called with a {@code RuntimePermission("getClassLoader")} - * permission to check that the caller is allowed to get access to the - * class loader.

- * * @apiNote This method does not return an {@code Optional} * because `null` must be used to represent the bootstrap class loader. * @@ -921,8 +885,6 @@ boolean addEnableNativeAccess(String name) { * * @throws IllegalArgumentException if a module of the given name is not * defined in this layer or any parent of this layer - * - * @throws SecurityException if denied by the security manager */ public ClassLoader findLoader(String name) { Optional om = findModule(name); diff --git a/src/java.base/share/classes/java/lang/Process.java b/src/java.base/share/classes/java/lang/Process.java index af6753a236bb2..3e4837d2e0253 100644 --- a/src/java.base/share/classes/java/lang/Process.java +++ b/src/java.base/share/classes/java/lang/Process.java @@ -753,8 +753,7 @@ public boolean isReleasable() { * * {@code Process} objects returned by {@link ProcessBuilder#start()} and * {@link Runtime#exec} implement {@code toHandle} as the equivalent of - * {@link ProcessHandle#of(long) ProcessHandle.of(pid)} including the - * check for a SecurityManager and {@code RuntimePermission("manageProcess")}. + * {@link ProcessHandle#of(long) ProcessHandle.of(pid)}. * * @implSpec * This implementation throws an instance of @@ -766,8 +765,6 @@ public boolean isReleasable() { * @return Returns a ProcessHandle for the Process * @throws UnsupportedOperationException if the Process implementation * does not support this operation - * @throws SecurityException if a security manager has been installed and - * it denies RuntimePermission("manageProcess") * @since 9 */ public ProcessHandle toHandle() { @@ -811,8 +808,6 @@ public ProcessHandle.Info info() { * direct children of the process * @throws UnsupportedOperationException if the Process implementation * does not support this operation - * @throws SecurityException if a security manager has been installed and - * it denies RuntimePermission("manageProcess") * @since 9 */ public Stream children() { @@ -837,8 +832,6 @@ public Stream children() { * are descendants of the process * @throws UnsupportedOperationException if the Process implementation * does not support this operation - * @throws SecurityException if a security manager has been installed and - * it denies RuntimePermission("manageProcess") * @since 9 */ public Stream descendants() { diff --git a/src/java.base/share/classes/java/lang/ProcessBuilder.java b/src/java.base/share/classes/java/lang/ProcessBuilder.java index e7d5d9debef69..c3cb9bfd14515 100644 --- a/src/java.base/share/classes/java/lang/ProcessBuilder.java +++ b/src/java.base/share/classes/java/lang/ProcessBuilder.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 2024, 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 @@ -329,23 +329,12 @@ public List command() { * *

The returned map is typically case-sensitive on all platforms. * - *

If a security manager exists, its - * {@link SecurityManager#checkPermission checkPermission} method - * is called with a - * {@link RuntimePermission}{@code ("getenv.*")} permission. - * This may result in a {@link SecurityException} being thrown. - * *

When passing information to a Java subprocess, * system properties * are generally preferred over environment variables. * * @return this process builder's environment * - * @throws SecurityException - * if a security manager exists and its - * {@link SecurityManager#checkPermission checkPermission} - * method doesn't allow access to the process environment - * * @see Runtime#exec(String[],String[],java.io.File) * @see System#getenv() */ @@ -1009,12 +998,6 @@ public ProcessBuilder redirectErrorStream(boolean redirectErrorStream) { * The minimal set of system dependent environment variables * may override the values provided in the environment. * - *

If there is a security manager, its - * {@link SecurityManager#checkExec checkExec} - * method is called with the first component of this object's - * {@code command} array as its argument. This may result in - * a {@link SecurityException} being thrown. - * *

Starting an operating system process is highly system-dependent. * Among the many things that can go wrong are: *