You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@struts.apache.org by ni...@apache.org on 2005/09/16 01:13:48 UTC
svn commit: r289342 - in /struts/taglib/trunk/src:
java/org/apache/struts/taglib/TagUtils.java
test/org/apache/struts/taglib/TestTagUtils.java
Author: niallp
Date: Thu Sep 15 16:13:37 2005
New Revision: 289342
URL: http://svn.apache.org/viewcvs?rev=289342&view=rev
Log:
Throw a NullPointerException with a useful message if the ModuleConfig cannot be found. Otherwise methods like TagUtils.pageURL() fail anyway with a NullPointerException with no clue as to why.
Modified:
struts/taglib/trunk/src/java/org/apache/struts/taglib/TagUtils.java
struts/taglib/trunk/src/test/org/apache/struts/taglib/TestTagUtils.java
Modified: struts/taglib/trunk/src/java/org/apache/struts/taglib/TagUtils.java
URL: http://svn.apache.org/viewcvs/struts/taglib/trunk/src/java/org/apache/struts/taglib/TagUtils.java?rev=289342&r1=289341&r2=289342&view=diff
==============================================================================
--- struts/taglib/trunk/src/java/org/apache/struts/taglib/TagUtils.java (original)
+++ struts/taglib/trunk/src/java/org/apache/struts/taglib/TagUtils.java Thu Sep 15 16:13:37 2005
@@ -422,7 +422,7 @@
}
// Look up the module configuration for this request
- ModuleConfig moduleConfig = instance.getModuleConfig(module, pageContext);
+ ModuleConfig moduleConfig = getModuleConfig(module, pageContext);
// Calculate the appropriate URL
StringBuffer url = new StringBuffer();
@@ -649,7 +649,7 @@
// in case of non-root context, otherwise length==1 (the slash)
if (contextPath.length() > 1) value.append(contextPath);
- ModuleConfig moduleConfig = ModuleUtils.getInstance().getModuleConfig(module, request, pageContext.getServletContext());
+ ModuleConfig moduleConfig = getModuleConfig(module, pageContext);
if ((moduleConfig != null) && (!contextRelative)) {
value.append(moduleConfig.getPrefix());
@@ -776,10 +776,18 @@
* @return the ModuleConfig object
*/
public ModuleConfig getModuleConfig(String module, PageContext pageContext) {
- return ModuleUtils.getInstance().getModuleConfig(
+ ModuleConfig config = ModuleUtils.getInstance().getModuleConfig(
module,
(HttpServletRequest) pageContext.getRequest(),
pageContext.getServletContext());
+
+ // ModuleConfig not found
+ if (config == null) {
+ throw new NullPointerException("Module '" + module + "' not found.");
+ }
+
+ return config;
+
}
/**
Modified: struts/taglib/trunk/src/test/org/apache/struts/taglib/TestTagUtils.java
URL: http://svn.apache.org/viewcvs/struts/taglib/trunk/src/test/org/apache/struts/taglib/TestTagUtils.java?rev=289342&r1=289341&r2=289342&view=diff
==============================================================================
--- struts/taglib/trunk/src/test/org/apache/struts/taglib/TestTagUtils.java (original)
+++ struts/taglib/trunk/src/test/org/apache/struts/taglib/TestTagUtils.java Thu Sep 15 16:13:37 2005
@@ -1,5 +1,5 @@
/*
- * Copyright 2004 The Apache Software Foundation.
+ * Copyright 2004-2005 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -1996,9 +1996,13 @@
new MockPageContext(mockServletConfig, mockHttpServletRequest,
mockHttpServletResponse);
-
- ModuleConfig foundModuleConfig = tagutils.getModuleConfig(mockPageContext);
- assertNull(foundModuleConfig);
+ ModuleConfig foundModuleConfig = null;
+ try {
+ foundModuleConfig = tagutils.getModuleConfig(mockPageContext);
+ fail("Expected ModuleConfig to not be found");
+ } catch(NullPointerException ignore) {
+ // expected result
+ }
mockHttpServletRequest.setAttribute(Globals.MODULE_KEY, moduleConfig);
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
For additional commands, e-mail: dev-help@struts.apache.org