【发布时间】:2015-07-23 10:42:12
【问题描述】:
问题
我使用 Abatis 作为 ORM。当我尝试插入包含特定字符串的 json 时,它会崩溃。
我已经从 Abatis 中提取了产生错误的代码:
代码
Map<String, Object> bindParams = new HashMap<String, Object>();
bindParams.put("id", "194fa0f2-9706-493f-97ab-4eb300a8e4ed");
bindParams.put("field", "{\"Messages\":\"ERRORE durante l'invocazione del servizio. 01 - Executor [java.util.concurrent.ThreadPoolExecutor@18a96588] did not accept task: org.springframework.aop.interceptor.AsyncExecutionInterceptor$1@14a7c67b\",\"Errors\":1}");
String sql = "UPDATE <TABLE> SET NoteAgente = #field# WHERE Id = #id#";
if (bindParams != null) {
Iterator<String> mapIterator = bindParams.keySet().iterator();
while (mapIterator.hasNext()) {
String key = mapIterator.next();
Object value = bindParams.get(key);
if(value instanceof String && value != null)
value = value.toString().replace("'", "''");
sql = sql.replaceAll("#" + key + "#", value == null ? "null"
: "'" + value.toString() + "'");
}
}
问题在于字符串 $1@14a7c67b 的 replaceAll 方法。你也可以调试它写
String s = "onetwothree";
s = s.replaceAll("one", "$1@14a7c67b");
它也会崩溃。
【问题讨论】:
标签: java android replace replaceall