37 lines
923 B
Plaintext
37 lines
923 B
Plaintext
=== How to fix it in Java SE
|
|
|
|
include::../../common/fix/code-rationale.adoc[]
|
|
|
|
==== Non-compliant code example
|
|
|
|
[source,java,diff-id=1,diff-type=noncompliant]
|
|
----
|
|
private static final Logger logger = Logger.getLogger("Logger");
|
|
|
|
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
|
|
|
|
String data = request.getParameter("data");
|
|
if(data != null){
|
|
logger.log(Level.INFO, "Data: {0} ", data);
|
|
}
|
|
}
|
|
----
|
|
|
|
==== Compliant solution
|
|
|
|
[source,java,diff-id=1,diff-type=compliant]
|
|
----
|
|
private static final Logger logger = Logger.getLogger("Logger");
|
|
|
|
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
|
|
|
|
String data = request.getParameter("data");
|
|
if(data != null){
|
|
data = data.replaceAll("[\n\r]", "_");
|
|
logger.log(Level.INFO, "Data: {0} ", data);
|
|
}
|
|
}
|
|
----
|
|
|
|
include::../../common/fix/how-does-this-work.adoc[]
|