[ 
https://issues.apache.org/jira/browse/HADOOP-19574?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18017950#comment-18017950
 ] 

ASF GitHub Bot commented on HADOOP-19574:
-----------------------------------------

szetszwo commented on PR #7892:
URL: https://github.com/apache/hadoop/pull/7892#issuecomment-3250102379

   @stoty , thanks for trying it out!  The code should look like below:
   ```java
   public class SubjectDoAsThread extends Thread {
     private final Runnable runnable;
     private Subject startSubject;
   
     public static class Builder {
       private ThreadGroup group;
       private String name;
       private Runnable runnable;
   
       public Builder setThread(Thread thread) {
         this.group = thread.getThreadGroup();
         this.name = thread.getName();
         this.runnable = thread;
         return this;
       }
   
       public SubjectDoAsThread build() {
         return new SubjectDoAsThread(group, name, runnable);
       }
     }
   
     private SubjectDoAsThread(ThreadGroup group, String name, Runnable 
runnable) {
       super(group, name);
       this.runnable = Objects.requireNonNull(runnable, "runnable == null");
     }
   
     @Override
     public final void start() {
       startSubject = SubjectUtil.current();
       super.start();
     }
   
     @Override
     public final void run() {
       SubjectUtil.doAs(startSubject, (PrivilegedAction<Void>) () -> {
         runnable.run();
         return null;
       });
     }
   }
   ```




> Restore Subject propagation semantics for Java 22+
> --------------------------------------------------
>
>                 Key: HADOOP-19574
>                 URL: https://issues.apache.org/jira/browse/HADOOP-19574
>             Project: Hadoop Common
>          Issue Type: Improvement
>            Reporter: Istvan Toth
>            Assignee: Istvan Toth
>            Priority: Critical
>              Labels: pull-request-available
>
> Java 22 breaks Subject propagation for new Threads (when SecurityManager is 
> not enabled).
> Previously, the Subject set by Subject.doAs() / Subject.callAs() 
> automatically propagated to any new Threads created (via new Thread(), not 
> Executors).
> With JDK22, this is no longer the case, new Threads do NOT inherit the 
> Subject.
> As Hadoop heavily relies on the original behavior, we somehow need to solve 
> this problem.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

---------------------------------------------------------------------
To unsubscribe, e-mail: common-issues-unsubscr...@hadoop.apache.org
For additional commands, e-mail: common-issues-h...@hadoop.apache.org

Reply via email to