2023-03-07 17:16:47 +01:00
|
|
|
== How to fix it in Java SE
|
|
|
|
|
|
|
|
=== Code examples
|
2022-08-26 17:37:39 +02:00
|
|
|
|
|
|
|
include::../../common/fix/code-rationale.adoc[]
|
|
|
|
|
2022-10-18 16:03:10 +02:00
|
|
|
==== Noncompliant code example
|
2022-09-15 10:28:08 +02:00
|
|
|
|
|
|
|
[source,java,diff-id=1,diff-type=noncompliant]
|
2022-08-26 17:37:39 +02:00
|
|
|
----
|
|
|
|
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){
|
2022-09-15 10:28:08 +02:00
|
|
|
logger.log(Level.INFO, "Data: {0} ", data);
|
2022-08-26 17:37:39 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
----
|
2022-09-15 10:28:08 +02:00
|
|
|
|
|
|
|
==== Compliant solution
|
|
|
|
|
|
|
|
[source,java,diff-id=1,diff-type=compliant]
|
2022-08-26 17:37:39 +02:00
|
|
|
----
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
----
|
|
|
|
|
2022-09-15 10:28:08 +02:00
|
|
|
include::../../common/fix/how-does-this-work.adoc[]
|