Page 1 of 1

About Question enthuware.ocpjp.v8.2.1552 :

Posted: Thu Sep 29, 2016 8:50 am
by lws963
Hi,

My problem with these questions about invalid OpenOption combinations is, that IMO the reason because the JavaDoc does not explicitly mention which combinations are invalid is that there are no global invalid combinations. It depends on the operation (read or write), and whether a file exists or not.

For example answer 4 states, that
new OpenOption[]{StandardOpenOption.APPEND, StandardOpenOption.CREATE_NEW}
This throws java.lang.UnsupportedOperationException: 'APPEND' not allowed.
This is true for an InputStream, but the Files.newBufferedWriter method accepts this combination if the file does not exist. The combination InputStream + APPEND is invalid, not the the combination of the the APPEND + CREATE_NEW.

Also answer 5:
new OpenOption[]{StandardOpenOption.READ, StandardOpenOption.SYNC}
Ideally, this should be an invalid combination (because when a file is opened for READ, there is nothing to synch) but it works.
The Files.newBufferedWriter method throws a java.lang.IllegalArgumentException: READ not allowed but it works with an InputStream. Again, the combination itself is not invalid, it just depends on the operation.

or did I miss something here?

Thanks

Re: About Question enthuware.ocpjp.v8.2.1552 :

Posted: Thu Sep 29, 2016 5:49 pm
by admin
You may be right. However, the exam does have questions that require you to figure out valid combinations without the context on the operation.
I think a candidate will have to make a best guess to answer such questions.

HTH,
Paul.

Re: About Question enthuware.ocpjp.v8.2.1552 :

Posted: Sun Oct 02, 2016 4:59 am
by lws963
Thanks for the info. Let's hope I won't have to guess....

BTW, I did some research, and I found only 4 cases, but they are all operation dependent:
- the Files.newInputStream() method throws UnsupportedOperationException for WRITE and APPEND.
- the Files.newBufferedWriter method throws IllegalArgumentException for READ and the combination of APPEND + TRUNCATE_EXISTING.

thanks,
Tamas