1 Reply Latest reply: May 1, 2013 11:57 PM by 1005621 RSS

    Richfaces 4.3.1 weblogic 10.3.5.0 duplicate key on deploy

    1005621
      Hi,

      I'm having trouble with richfaces 4.3.1 on weblogic 10.3.5.0, on deploy the following exception happens:

      java.lang.RuntimeException: com.sun.faces.config.ConfigurationException: CONFIGURATION FAILED! duplicate key: class javax.faces.validator.LongRangeValidator
      at com.sun.faces.config.ConfigureListener.contextInitialized(ConfigureListener.java:290)
      at weblogic.servlet.internal.EventsManager$FireContextListenerAction.run(EventsManager.java:481)
      at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
      at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:120)
      at weblogic.servlet.internal.EventsManager.notifyContextCreatedEvent(EventsManager.java:181)
      Truncated. see log file for complete stacktrace
      Caused By: com.sun.faces.config.ConfigurationException: CONFIGURATION FAILED! duplicate key: class javax.faces.validator.LongRangeValidator
      at com.sun.faces.config.ConfigManager.initialize(ConfigManager.java:351)
      at com.sun.faces.config.ConfigureListener.contextInitialized(ConfigureListener.java:222)
      at weblogic.servlet.internal.EventsManager$FireContextListenerAction.run(EventsManager.java:481)
      at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
      at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:120)
      Truncated. see log file for complete stacktrace
      Caused By: java.lang.IllegalArgumentException: duplicate key: class javax.faces.validator.LongRangeValidator
      at com.google.common.base.Preconditions.checkArgument(Preconditions.java:115)
      at com.google.common.collect.RegularImmutableMap.<init>(RegularImmutableMap.java:72)
      at com.google.common.collect.ImmutableMap$Builder.fromEntryList(ImmutableMap.java:245)
      at com.google.common.collect.ImmutableMap$Builder.build(ImmutableMap.java:231)
      at org.richfaces.javascript.ClientServiceConfigParser.parseConfig(ClientServiceConfigParser.java:53)

      I had a look inside ClientServiceConfigParser and debugged it and I found that it ended up loading /META-INF/csv.xml twice from richfaces-components-ui-4.3.1.Final.jar

      The problem happens on line 45 when it calls Enumeration<URL> resources = loader.getResources(name);, because that ends up returning /META-INF/csv.xml twice because it returns a http://javasourcecode.org/html/open-source/jdk/jdk-6u23/sun/misc/CompoundEnumeration.html which seems to have 2 copies.

      This is the richfaces method in question:

      public static Map<Class<?>, LibraryFunction> parseConfig(String name) {
      ClassLoader loader = Thread.currentThread().getContextClassLoader();
      if (null == loader) {
      loader = ClientServiceConfigParser.class.getClassLoader();
      }
      Builder<Class<?>, LibraryFunction> resultBuilder = ImmutableMap.builder();
      try {
      Enumeration<URL> resources = loader.getResources(name);
      while (resources.hasMoreElements()) {
      URL url = (URL) resources.nextElement();
      resultBuilder.putAll(parse(loader, url));
      }
      } catch (IOException e) {
      return Collections.emptyMap();
      }
      return resultBuilder.build();
      }

      It seems something to do with Weblogic's ChangeAwareClassLoader (+weblogic.utils.classloaders.ChangeAwareClassLoader+). Because inside org.richfaces.javascript.ClientServiceConfigParser.parseConfig(String) when it runs ClassLoader loader = Thread.currentThread().getContextClassLoader(); it ends up returning the ChangeAwareClassLoader which happens to get 2 copies of the same resource. However if I null out the loader (using a debugger) so that it runs loader = ClientServiceConfigParser.class.getClassLoader();, then it ends up with a different classloader: weblogic.utils.classloaders.GenericClassLoader. Which doesn't get 2 copies of the same resource.

      Any idea how to get around this?

      I am using maven if it makes any difference.

      Thanks,

      -Joel

      P.S. I have already posted at the richfaces forum, but I haven't got any replies yet: [https://community.jboss.org/message/810397]