About Question enthuware.ocpjp.v11.2.3638 :

Help and support on OCA OCP Java Programmer Certification Questions
1Z0-808, 1Z0-809, 1Z0-815, 1Z0-816, 1Z0-817

Moderator: admin

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: 9358
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
If you like our products and services, please help us by posting your review here.

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: 9358
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!
If you like our products and services, please help us by posting your review here.

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: 9358
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!
If you like our products and services, please help us by posting your review here.

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: 9358
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.
If you like our products and services, please help us by posting your review here.

Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 8 guests