Question: Can you explain why the bottom one is preferred? We are studying security vulnerabilities. Noncompliant void readData() throws IOException{ BufferedReader br = new BufferedReader(new InputStreamReader(new
Can you explain why the bottom one is preferred? We are studying security vulnerabilities.
Noncompliant
void readData() throws IOException{ BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream("file"))); String data = br.readLine(); }
Compliant
void readData2() { ByteBuffer buffer = ByteBuffer.allocateDirect(16 * 1024); try(FileChannel rdr = (new FileInputStream ("file")).getChannel()){ while (rdr.read(buffer) > 0) { //Do something buffer.clear(); } }catch (Throwable e) { //Handle error } }
Step by Step Solution
There are 3 Steps involved in it
In the context of security vulnerabilities the compliant code snippet is preferred over the noncompliant one due to the following reasons Resource Lea... View full answer
Get step-by-step solutions from verified subject matter experts
