| Summary: | regex issue with CustomTableRowDiscoveryComponent.formatMessage | ||
|---|---|---|---|
| Product: | [Other] RHQ Project | Reporter: | Elias Ross <genman> |
| Component: | Plugins | Assignee: | Heiko W. Rupp <hrupp> |
| Status: | CLOSED UPSTREAM | QA Contact: | Mike Foley <mfoley> |
| Severity: | unspecified | Docs Contact: | |
| Priority: | medium | ||
| Version: | 4.3 | CC: | hrupp |
| Target Milestone: | --- | ||
| Target Release: | RHQ 4.3.0 | ||
| Hardware: | Unspecified | ||
| OS: | Linux | ||
| Whiteboard: | |||
| Fixed In Version: | Doc Type: | Bug Fix | |
| Doc Text: | Story Points: | --- | |
| Clone Of: | Environment: | ||
| Last Closed: | 2011-11-03 18:37:40 UTC | Type: | --- |
| Regression: | --- | Mount Type: | --- |
| Documentation: | --- | CRM: | |
| Verified Versions: | Category: | --- | |
| oVirt Team: | --- | RHEL 7.3 requirements from Atomic Host: | |
| Cloudforms Team: | --- | Target Upstream Version: | |
Just to be clear, the solution worked for me.
In git format:
diff --git a/modules/plugins/database/src/main/java/org/rhq/plugins/database/CustomTableRowDiscoveryComponent.java b/modules/plugins/database/src/main/java/org/rhq/plugins/databa
index e4d9392..630b575 100644
--- a/modules/plugins/database/src/main/java/org/rhq/plugins/database/CustomTableRowDiscoveryComponent.java
+++ b/modules/plugins/database/src/main/java/org/rhq/plugins/database/CustomTableRowDiscoveryComponent.java
@@ -25,6 +25,8 @@ import java.sql.Statement;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
+import java.util.regex.Matcher;
+
import org.rhq.core.domain.configuration.Configuration;
import org.rhq.core.domain.configuration.PropertySimple;
import org.rhq.core.pluginapi.inventory.DiscoveredResourceDetails;
@@ -58,7 +60,7 @@ public class CustomTableRowDiscoveryComponent implements ResourceDiscoveryCompon
if (resourceName == null) {
throw new InvalidPluginConfigurationException("The 'name' connection property has to be specified.");
}
-
+
statement = conn.createStatement();
resultSet = statement.executeQuery("SELECT * FROM " + table);
@@ -97,6 +99,7 @@ public class CustomTableRowDiscoveryComponent implements ResourceDiscoveryCompon
* @return the formatted text with variables replaced
*/
public static String formatMessage(String message, String key) {
+ key = Matcher.quoteReplacement(key);
message = message.replaceAll("\\{key\\}", key);
return message;
}
d06c57c in master |
Description of problem: 2011-11-01 22:01:28,098 WARN [InventoryManager.discovery-1] (rhq.core.pc.inventory.InventoryManager)- Failure during discovery for [Oracle User] Resources - failed after 7 ms. java.lang.Exception: Discovery component invocation failed. at org.rhq.core.pc.util.DiscoveryComponentProxyFactory$ComponentInvocationThread.call(DiscoveryComponentProxyFactory.java:285) at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303) at java.util.concurrent.FutureTask.run(FutureTask.java:138) at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) at java.lang.Thread.run(Thread.java:619) Caused by: java.lang.IllegalArgumentException: Illegal group reference at java.util.regex.Matcher.appendReplacement(Matcher.java:713) at java.util.regex.Matcher.replaceAll(Matcher.java:813) at java.lang.String.replaceAll(String.java:2189) at org.rhq.plugins.database.CustomTableRowDiscoveryComponent.formatMessage(CustomTableRowDiscoveryComponent.java:100) at org.rhq.plugins.database.CustomTableRowDiscoveryComponent.discoverResources(CustomTableRowDiscoveryComponent.java:70) at sun.reflect.GeneratedMethodAccessor47.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.rhq.core.pc.util.DiscoveryComponentProxyFactory$ComponentInvocationThread.call(DiscoveryComponentProxyFactory.java:281) ... 5 more Version-Release number of selected component (if applicable): commit eae6e470b1ee7e9f72ca6a0836bad48bd2d4ff1a 4.3.0-SNAPSHOT How reproducible: Every time? Steps to Reproduce: 1. Install Oracle plugin 2. 3. Additional info: If key contains a $, e.g. if on Oracle /** * Format a message with {<key>} formatted replacement keys. * * @param message the message to format * * @return the formatted text with variables replaced */ public static String formatMessage(String message, String key) { message = message.replaceAll("\\{key\\}", key); return message; } Solution? public static String formatMessage(String message, String key) { key = Matcher.quoteReplacement(key); message = message.replaceAll("\\{key\\}", key); return message; } Probably should apply to other sites using String.replaceAll construct.