About Question enthuware.ocpjp.v11.2.3638 :

All the posts and topics that contain only an error report will be moved here after the error is corrected. This is to ensure that when users view a question in ETS Viewer, the "Discuss" button will not indicate the presence of a discussion that adds no value to the question.

Moderators: Site Manager, fjwalraven

Post Reply
darshanjoshi
Posts: 1
Joined: Wed Apr 07, 2021 3:18 am
Contact:

About Question enthuware.ocpjp.v11.2.3638 :

Post by darshanjoshi »

As AccessController.doPrivileged method is not returning void, so below code will not compile.

public void setApprovedUsers(final List<String> userids) {
return AccessController.doPrivileged((PrivilegedAction<Void>) () -> {
this.userManager.setApprovedUsers(userids);
return null;
});
}

admin
Site Admin
Posts: 10384
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocpjp.v11.2.3638 :

Post by admin »

doPrivileged returns whatever PrivilegedAction's run method returns (given by the type of PrivilegedAction). Here, it returns Void because PrivilegedAction is typed to <Void>.
You may also check the example given here: https://docs.oracle.com/javase/8/docs/t ... leged.html

minajev3
Posts: 18
Joined: Fri Feb 05, 2021 3:37 am
Contact:

Re: About Question enthuware.ocpjp.v11.2.3638 :

Post by minajev3 »

Sorry but I am pretty sure your guess is wrong
because if we just pass unmodifiableList - user(customer) will still have control over it using his original list
but the main rule is not trust to users and dont allow them more than necessary.

admin
Site Admin
Posts: 10384
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocpjp.v11.2.3638 :

Post by admin »

You are right. It should use List.of instead of Collections.unmodifiableList. Fixed.
thank you for your feedback!

palmada
Posts: 2
Joined: Tue Apr 13, 2021 4:22 pm
Contact:

Re: About Question enthuware.ocpjp.v11.2.3638 :

Post by palmada »

While working on a code cleaup project fo
Small typo

admin
Site Admin
Posts: 10384
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocpjp.v11.2.3638 :

Post by admin »

Fixed.
thank you for your feedback!

driesva
Posts: 1
Joined: Sun May 02, 2021 9:33 am
Contact:

Re: About Question enthuware.ocpjp.v11.2.3638 :

Post by driesva »

IMHO List.of(userids) is not correct, it creates a List of a List...

admin
Site Admin
Posts: 10384
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocpjp.v11.2.3638 :

Post by admin »

You are right. It should be copyOf.

Post Reply

Who is online

Users browsing this forum: No registered users and 9 guests