Return to site
JAVA CERTIFICATION QUESTION: Secure coding
Here’s what happens when good code meets bad people.
·
You are developing a highly loaded, multithreaded stock-quote analysis application.
During a security audit, you were advised to make a defensive copy of stock-quote data as you receive it for analysis,
isolating the calculations from any modifications made to the original input data.
Given this StockQuote class:
class StockQuote { public StockQuote(String n, LocalDateTime t, Double p) { name = n; time = t; price = p; } private String name; private LocalDateTime time; private Double price; // getters and setters hidden for brevity }
and this method, which should protect itself by making a copy:
public void analyzeQuotes(ArrayList<StockQuote> sqList) { List<StockQuote> sqListProtected = … // make a defensive copy }
Which code line (if any) can protect you from malicious modifications made to the stock-quote data during the processing? Choose one.
A.
List<StockQuote>)sqList.clone();
B.
new ArrayList<StockQuote>(sqList);C.
(List)sqList.stream()
.map(s -> s.clone())
.collect(Collectors.toList());D.
sqList.stream()
.map(s -> s.clone())
.collect(Collectors.toCollection(ArrayList::new));E. None of the above
·Ǝ sᴉ ɹǝʍsuɐ ʇɔǝɹɹoɔ ǝɥꓕ