Question: A software security expert reviews the following Java code based on best practices and provides the following answer. Is it True or False? Exercise 1
A software security expert reviews the following Java code based on best practices and provides the following answer. Is it True or False?
Exercise Given the below Java method, are there any syntactical semantical, logical errors? What can be improved from the securitycompliance perspective? If there are securityrelated issues, how can we fix them?
class MyClass
private int a l;
private void doLogic
int a;
Answer.
This securitynoncompliant code example reuses the name of the yal instance field in the scope of an instance method.
The resulting behavior can be classified as shadowing; the method variable renders the class variable inaccessible within the scope of the method.
Example: assigning to this.val from within the method does not affect the value of the class variable.
class MyVector
private int yal underlineunderline;
private void doLogic
int newValue;
This securitycompliant solution eliminates shadowing by changing the name of the variable defined in the method scope from yal to newValue.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
