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

1 Expert Approved Answer
Step: 1 Unlock

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

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!