Bug 750665 - regex issue with CustomTableRowDiscoveryComponent.formatMessage
Summary: regex issue with CustomTableRowDiscoveryComponent.formatMessage
Keywords:
Status: CLOSED UPSTREAM
Alias: None
Product: RHQ Project
Classification: Other
Component: Plugins
Version: 4.3
Hardware: Unspecified
OS: Linux
medium
unspecified vote
Target Milestone: ---
: RHQ 4.3.0
Assignee: Heiko W. Rupp
QA Contact: Mike Foley
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2011-11-01 22:37 UTC by Elias Ross
Modified: 2011-11-03 18:37 UTC (History)
1 user (show)

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2011-11-03 18:37:40 UTC


Attachments (Terms of Use)

Description Elias Ross 2011-11-01 22:37:03 UTC
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.

Comment 1 Elias Ross 2011-11-02 00:05:47 UTC
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;
     }

Comment 2 Heiko W. Rupp 2011-11-03 12:08:10 UTC
d06c57c in master


Note You need to log in before you can comment on or make changes to this bug.