/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2019 Nordix Foundation.
+ * Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
package org.onap.policy.models.dao.converters;
+import com.google.re2j.Pattern;
import javax.persistence.AttributeConverter;
import javax.persistence.Converter;
import javax.xml.bind.annotation.adapters.XmlAdapter;
@Converter
public class CDataConditioner extends XmlAdapter<String, String> implements AttributeConverter<String, String> {
+ private static final Pattern TRAILING_SPACE_PAT = Pattern.compile("\\s+$");
private static final String NL = "\n";
@Override
if (in == null) {
return null;
} else {
- return in.replaceAll("\\s+$", "").replaceAll("\\r?\\n", NL);
+ return TRAILING_SPACE_PAT.matcher(in).replaceAll("").replaceAll("\\r?\\n", NL);
}
}
}
final var mg = getEntityManager();
long size = 0;
try {
+ /*
+ * The invoking code only passes well-known classes into this method, thus
+ * disabling the sonar about SQL injection.
+ */
size = mg.createQuery("SELECT COUNT(c) FROM " + someClass.getSimpleName() + " c", Long.class)
- .getSingleResult();
+ .getSingleResult(); // NOSONAR
} finally {
mg.close();
}