Author: ajaquith
Date: Mon May 4 23:51:30 2009
New Revision: 771503
URL: http://svn.apache.org/viewvc?rev=771503&view=rev
Log:
Encountered problem with new ReferenceManager (probably related to Priha) that
causes heap exhaustion. ReferenceManager includes a few (temporary) diagnostics
for this. It also changes the method signatures for getRefersTo and
getReferredBy to return lists of WikiPath. Several plugins were changed to
accommodate this.
Modified:
incubator/jspwiki/trunk/src/java/org/apache/wiki/ReferenceManager.java
incubator/jspwiki/trunk/src/java/org/apache/wiki/plugin/ReferringPagesPlugin.java
incubator/jspwiki/trunk/src/java/org/apache/wiki/plugin/UndefinedPagesPlugin.java
incubator/jspwiki/trunk/src/java/org/apache/wiki/plugin/UnusedPagesPlugin.java
incubator/jspwiki/trunk/tests/java/org/apache/wiki/ReferenceManagerTest.java
incubator/jspwiki/trunk/tests/java/org/apache/wiki/WikiEngineTest.java
Modified: incubator/jspwiki/trunk/src/java/org/apache/wiki/ReferenceManager.java
URL:
http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/java/org/apache/wiki/ReferenceManager.java?rev=771503&r1=771502&r2=771503&view=diff
==============================================================================
--- incubator/jspwiki/trunk/src/java/org/apache/wiki/ReferenceManager.java
(original)
+++ incubator/jspwiki/trunk/src/java/org/apache/wiki/ReferenceManager.java Mon
May 4 23:51:30 2009
@@ -463,13 +463,13 @@
* @return A list of Strings, where each names a page that hasn't been
* created
*/
- public List<String> findUncreated() throws RepositoryException
+ public List<WikiPath> findUncreated() throws RepositoryException
{
String[] linkStrings = getFromProperty( NOT_CREATED,
PROPERTY_NOT_CREATED );
- List<String> links = new ArrayList<String>();
+ List<WikiPath> links = new ArrayList<WikiPath>();
for( String link : linkStrings )
{
- links.add( link );
+ links.add( WikiPath.valueOf( link ) );
}
return links;
}
@@ -484,13 +484,13 @@
* @return A list of Strings, where each names a page that hasn't been
* created
*/
- public List<String> findUnreferenced() throws RepositoryException
+ public List<WikiPath> findUnreferenced() throws RepositoryException
{
String[] linkStrings = getFromProperty( NOT_REFERENCED,
PROPERTY_NOT_REFERENCED );
- List<String> links = new ArrayList<String>();
+ List<WikiPath> links = new ArrayList<WikiPath>();
for( String link : linkStrings )
{
- links.add( link );
+ links.add( WikiPath.valueOf( link ) );
}
return links;
}
@@ -511,6 +511,11 @@
*/
public List<WikiPath> getReferredBy( WikiPath destination ) throws
ProviderException
{
+ if ( destination == null )
+ {
+ throw new IllegalArgumentException( "Destination cannot be null!"
);
+ }
+
try
{
String jcrPath = getReferencedByJCRNode( destination );
@@ -547,6 +552,11 @@
*/
public List<WikiPath> getRefersTo( WikiPath source ) throws
ProviderException
{
+ if ( source == null )
+ {
+ throw new IllegalArgumentException( "Source cannot be null!" );
+ }
+
try
{
String jcrPath = ContentManager.getJCRPath( source );
@@ -631,9 +641,13 @@
/**
* Builds and returns the path used to store the ReferredBy data
*/
- private String getReferencedByJCRNode( WikiPath name )
+ private String getReferencedByJCRNode( WikiPath path )
{
- return REFERRED_BY + "/" + name.getSpace() + "/" + name.getPath();
+ if ( path == null )
+ {
+ throw new IllegalArgumentException( "Path cannot be null!" );
+ }
+ return REFERRED_BY + "/" + path.getSpace() + "/" + path.getPath();
}
/**
@@ -668,6 +682,11 @@
*/
private void renameLinksTo( WikiPath oldPath, WikiPath newPath ) throws
ProviderException, RepositoryException
{
+ if ( oldPath == null || newPath == null )
+ {
+ throw new IllegalArgumentException( "oldPath and newPath cannot be
null!" );
+ }
+
List<WikiPath> referrers = getReferredBy( oldPath );
if( referrers.isEmpty() )
return; // No referrers
@@ -728,6 +747,11 @@
*/
private WikiPath resolvePage( WikiPath path ) throws ProviderException
{
+ if ( path == null )
+ {
+ throw new IllegalArgumentException( "Path cannot be null!" );
+ }
+
WikiPath finalPath = m_engine.getFinalPageName( path );
return finalPath == null ? path : finalPath;
}
@@ -746,6 +770,11 @@
*/
protected void addReferredBy( WikiPath page, WikiPath from ) throws
RepositoryException
{
+ if ( page == null || from == null )
+ {
+ throw new IllegalArgumentException( "Page and from cannot be
null!" );
+ }
+
// Make sure the 'referredBy' root exists
initReferenceMetadata();
@@ -770,6 +799,12 @@
*/
protected void addToProperty( String jcrNode, String property, String
newValue, boolean addAgain ) throws RepositoryException
{
+ if ( jcrNode == null || property == null || newValue == null )
+ {
+ throw new IllegalArgumentException( "jcrNode, property and
newValue cannot be null!" );
+ }
+ checkValueString( newValue );
+
// Retrieve (or create) the destination node for the page
ContentManager cm = m_engine.getContentManager();
Session s = cm.getCurrentSession();
@@ -795,10 +830,15 @@
Value[] values = p.getValues();
for( int i = 0; i < values.length; i++ )
{
- newValues.add( values[i].getString() );
- if( values[i].getString().equals( newValue ) )
+ String valueString = values[i].getString();
+ checkValueString( valueString );
+ if( valueString != null && valueString.length() > 0 )
{
- notFound = false;
+ newValues.add( valueString );
+ if( newValue.equals( valueString ) )
+ {
+ notFound = false;
+ }
}
}
if( notFound || addAgain )
@@ -834,6 +874,11 @@
*/
protected List<WikiPath> extractLinks( WikiPath path ) throws
PageNotFoundException, ProviderException
{
+ if ( path == null )
+ {
+ throw new IllegalArgumentException( "Path cannot be null!" );
+ }
+
// Set up a streamlined parser to collect links
WikiPage page = m_engine.getPage( path );
LinkCollector localCollector = new LinkCollector();
@@ -880,6 +925,11 @@
*/
protected String[] getFromProperty( String jcrNode, String property )
throws RepositoryException
{
+ if ( jcrNode == null || property == null )
+ {
+ throw new IllegalArgumentException( "jcrNode and property cannot
be null!" );
+ }
+
// Retrieve the destination node for the page
ContentManager cm = m_engine.getContentManager();
Node node = null;
@@ -901,6 +951,7 @@
stringValues = new String[values.length];
for( int i = 0; i < values.length; i++ )
{
+ checkValueString( values[i].getString() );
stringValues[i] = values[i].getString();
}
}
@@ -926,6 +977,12 @@
*/
protected void removeFromProperty( String jcrNode, String property, String
value ) throws RepositoryException
{
+ if ( jcrNode == null || property == null || value == null )
+ {
+ throw new IllegalArgumentException( "jcrNode, property and value
cannot be null!" );
+ }
+ checkValueString( value );
+
// Retrieve (or create) the destination node for the page
ContentManager cm = m_engine.getContentManager();
Session s = cm.getCurrentSession();
@@ -950,17 +1007,19 @@
Value[] values = p.getValues();
for( int i = 0; i < values.length; i++ )
{
- if( !values[i].getString().equals( value ) )
+ String valueString = values[i].getString();
+ checkValueString( valueString );
+ if( valueString != null && valueString.length() > 0 &&
!value.equals( valueString ) )
{
- newValues.add( values[i].getString() );
+ newValues.add( valueString );
}
}
if( newValues.size() == 0 )
{
- // This seems like a hack, but zero-length arrays don't seem to
- // work
- // unless we remove the property entirely first.
+ // There seems to be a bug in Priha that causes property files
to bloat,
+ // so we remove the property first, then re-add it
p.remove();
+ s.save();
}
}
catch( PathNotFoundException e )
@@ -975,6 +1034,29 @@
}
s.save();
}
+
+ /**
+ * Strictly for troubleshooting: we look for a non-Roman value in the
string and throw an exception.
+ * @param v
+ */
+ private void checkValueString( String v )
+ {
+ boolean highChar = false;
+ for ( int i = 0; i < v.length(); i++ )
+ {
+ int ch = v.charAt( i );
+ if ( ch < 32 || ch > 127 )
+ {
+ highChar = true;
+ break;
+// throw new IllegalStateException( "Bad character in string "
+ v +", char='" + (char)ch + "' int=" + ch );
+ }
+ }
+ if ( highChar )
+ {
+ Thread.currentThread().dumpStack();
+ }
+ }
/**
* <p>
@@ -995,6 +1077,11 @@
*/
protected void removeLinks( WikiPath page ) throws ProviderException,
RepositoryException
{
+ if ( page == null )
+ {
+ throw new IllegalArgumentException( "Page cannot be null!" );
+ }
+
// Get old linked pages; add to 'unreferenced list' if needed
List<WikiPath> referenced = getRefersTo( page );
for( WikiPath ref : referenced )
@@ -1076,6 +1163,10 @@
*/
protected void setLinks( WikiPath source, List<WikiPath> destinations )
throws ProviderException, RepositoryException
{
+ if ( source == null || destinations == null )
+ {
+ throw new IllegalArgumentException( "Source and destinations
cannot be null!" );
+ }
Session s = m_cm.getCurrentSession();
@@ -1156,6 +1247,11 @@
*/
protected void setRefersTo( WikiPath source, List<WikiPath> destinations )
throws ProviderException, RepositoryException
{
+ if ( source == null || destinations == null )
+ {
+ throw new IllegalArgumentException( "Source and destinations
cannot be null!" );
+ }
+
if( !m_cm.pageExists( source ) )
{
return;
Modified:
incubator/jspwiki/trunk/src/java/org/apache/wiki/plugin/ReferringPagesPlugin.java
URL:
http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/java/org/apache/wiki/plugin/ReferringPagesPlugin.java?rev=771503&r1=771502&r2=771503&view=diff
==============================================================================
---
incubator/jspwiki/trunk/src/java/org/apache/wiki/plugin/ReferringPagesPlugin.java
(original)
+++
incubator/jspwiki/trunk/src/java/org/apache/wiki/plugin/ReferringPagesPlugin.java
Mon May 4 23:51:30 2009
@@ -21,7 +21,6 @@
package org.apache.wiki.plugin;
import java.text.MessageFormat;
-import java.util.ArrayList;
import java.util.Collection;
import java.util.Map;
import java.util.ResourceBundle;
@@ -112,19 +111,14 @@
if( links != null && links.size() > 0 )
{
- // FIXME: Having to copy all of these is kinda stupid.
- Collection<String> tmpList = new ArrayList<String>();
-
- for( WikiPath wn : links ) tmpList.add( wn.toString() );
-
- tmpList= filterCollection( tmpList );
- wikitext = wikitizeCollection( tmpList, m_separator, items );
+ links = filterCollection( links );
+ wikitext = wikitizeCollection( links , m_separator, items );
result.append( makeHTML( context, wikitext ) );
- if( items < tmpList.size() && items > 0 )
+ if( items < links.size() && items > 0 )
{
- Object[] args = { "" + ( tmpList.size() - items) };
+ Object[] args = { "" + ( links.size() - items) };
extras = MessageFormat.format(extras, args);
result.append( "<br />" );
Modified:
incubator/jspwiki/trunk/src/java/org/apache/wiki/plugin/UndefinedPagesPlugin.java
URL:
http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/java/org/apache/wiki/plugin/UndefinedPagesPlugin.java?rev=771503&r1=771502&r2=771503&view=diff
==============================================================================
---
incubator/jspwiki/trunk/src/java/org/apache/wiki/plugin/UndefinedPagesPlugin.java
(original)
+++
incubator/jspwiki/trunk/src/java/org/apache/wiki/plugin/UndefinedPagesPlugin.java
Mon May 4 23:51:30 2009
@@ -29,6 +29,7 @@
import org.apache.wiki.ReferenceManager;
import org.apache.wiki.WikiContext;
import org.apache.wiki.api.PluginException;
+import org.apache.wiki.content.WikiPath;
/**
@@ -50,7 +51,7 @@
throws PluginException
{
ReferenceManager refmgr = context.getEngine().getReferenceManager();
- Collection<String> links;
+ Collection<WikiPath> links;
try
{
links = refmgr.findUncreated();
@@ -63,7 +64,7 @@
super.initialize( context, params );
- TreeSet<String> sortedSet = new TreeSet<String>();
+ TreeSet<WikiPath> sortedSet = new TreeSet<WikiPath>();
links = filterCollection( links );
Modified:
incubator/jspwiki/trunk/src/java/org/apache/wiki/plugin/UnusedPagesPlugin.java
URL:
http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/java/org/apache/wiki/plugin/UnusedPagesPlugin.java?rev=771503&r1=771502&r2=771503&view=diff
==============================================================================
---
incubator/jspwiki/trunk/src/java/org/apache/wiki/plugin/UnusedPagesPlugin.java
(original)
+++
incubator/jspwiki/trunk/src/java/org/apache/wiki/plugin/UnusedPagesPlugin.java
Mon May 4 23:51:30 2009
@@ -30,6 +30,7 @@
import org.apache.wiki.ReferenceManager;
import org.apache.wiki.WikiContext;
import org.apache.wiki.api.PluginException;
+import org.apache.wiki.content.WikiPath;
import org.apache.wiki.util.TextUtil;
@@ -59,7 +60,7 @@
throws PluginException
{
ReferenceManager refmgr = context.getEngine().getReferenceManager();
- Collection<String> links;
+ Collection<WikiPath> links;
try
{
links = refmgr.findUnreferenced();
@@ -77,11 +78,11 @@
{
// remove links to attachments (recognizable by a slash in it)
// FIXME: In 3.0, this assumption is going to fail. FIXME3.0
- Iterator<String> iterator = links.iterator();
+ Iterator<WikiPath> iterator = links.iterator();
while( iterator.hasNext() )
{
- String link = iterator.next();
- if (link.indexOf("/")!=-1)
+ WikiPath link = iterator.next();
+ if ( link.getPath().indexOf("/")!=-1 )
{
iterator.remove();
}
@@ -90,7 +91,7 @@
super.initialize( context, params );
- TreeSet<String> sortedSet = new TreeSet<String>();
+ TreeSet<WikiPath> sortedSet = new TreeSet<WikiPath>();
links = filterCollection( links );
Modified:
incubator/jspwiki/trunk/tests/java/org/apache/wiki/ReferenceManagerTest.java
URL:
http://svn.apache.org/viewvc/incubator/jspwiki/trunk/tests/java/org/apache/wiki/ReferenceManagerTest.java?rev=771503&r1=771502&r2=771503&view=diff
==============================================================================
---
incubator/jspwiki/trunk/tests/java/org/apache/wiki/ReferenceManagerTest.java
(original)
+++
incubator/jspwiki/trunk/tests/java/org/apache/wiki/ReferenceManagerTest.java
Mon May 4 23:51:30 2009
@@ -208,13 +208,13 @@
{
engine.saveText( "Foobar2", "[TestPage]" );
- List<String> c = mgr.findUnreferenced();
+ List<WikiPath> c = mgr.findUnreferenced();
assertEquals( 0, c.size() );
engine.saveText( "Foobar2", "norefs" );
c = mgr.findUnreferenced();
assertEquals( 1, c.size() );
- assertEquals( "Main:TestPage", c.get( 0 ) );
+ assertEquals( WikiPath.valueOf( "Main:TestPage" ), c.get( 0 ) );
}
public void testCircularRefs() throws Exception
@@ -594,16 +594,16 @@
public void testUncreated() throws Exception
{
- List<String> c = mgr.findUncreated();
+ List<WikiPath> c = mgr.findUncreated();
assertEquals( 1, c.size());
- assertEquals( "Main:Foobar2", c.get( 0 ) );
+ assertEquals( WikiPath.valueOf( "Main:Foobar2" ), c.get( 0 ) );
}
public void testUnreferenced() throws Exception
{
- List<String> c = mgr.findUnreferenced();
+ List<WikiPath> c = mgr.findUnreferenced();
assertEquals( 1, c.size() );
- assertEquals( "Main:TestPage", c.get( 0 ) );
+ assertEquals( WikiPath.valueOf( "Main:TestPage" ), c.get( 0 ) );
}
public void testPluralExists() throws Exception
@@ -631,9 +631,9 @@
public void testUpdateFoobar2s() throws Exception
{
engine.saveText( "Foobar2s", "qwertz" );
- List<String> c = mgr.findUncreated();
+ List<WikiPath> c = mgr.findUncreated();
assertEquals( 1, c.size() );
- assertTrue( c.contains( "Main:Foobar2" ) );
+ assertTrue( c.contains( WikiPath.valueOf( "Main:Foobar2" ) ) );
Collection<WikiPath> w = mgr.getReferredBy( WikiPath.valueOf(
"Foobar2s" ));
assertEquals( 0, w.size() );
@@ -649,13 +649,31 @@
public void testUpdatePluralOnlyRef() throws Exception
{
engine.saveText( "TestPage", "Reference to [Foobars]." );
- List<String> c = mgr.findUnreferenced();
+ List<WikiPath> c = mgr.findUnreferenced();
assertEquals( 1, c.size() );
- assertEquals( "Main:TestPage", c.get( 0 ) );
+ assertEquals( WikiPath.valueOf( "Main:TestPage" ), c.get( 0 ) );
Collection<WikiPath> p = mgr.getReferredBy( WikiPath.valueOf( "Foobar"
));
assertEquals( 2, p.size() );
}
+ /**
+ * A placeholder for methods that try to reproduce the Unicode issues
plaguing the
+ * current build. So far, this does not produce the desired side-effects.
+ * @throws Exception
+ */
+ public void testPropertyStress() throws Exception
+ {
+ String jcrPath = "/PropertyStress";
+
+ String scandic = "ÄitiSyöÖljyä";
+ mgr.addToProperty( jcrPath, "foo",scandic, false );
+
+ for ( int i = 0; i < 10; i++ )
+ {
+ mgr.addToProperty( jcrPath, "foo",scandic, false );
+ }
+ }
+
}
\ No newline at end of file
Modified: incubator/jspwiki/trunk/tests/java/org/apache/wiki/WikiEngineTest.java
URL:
http://svn.apache.org/viewvc/incubator/jspwiki/trunk/tests/java/org/apache/wiki/WikiEngineTest.java?rev=771503&r1=771502&r2=771503&view=diff
==============================================================================
--- incubator/jspwiki/trunk/tests/java/org/apache/wiki/WikiEngineTest.java
(original)
+++ incubator/jspwiki/trunk/tests/java/org/apache/wiki/WikiEngineTest.java Mon
May 4 23:51:30 2009
@@ -701,9 +701,9 @@
m_engine.saveText( NAME1, "[Foobar]" );
m_engine.getText( NAME1 ); // Ensure that page is cached.
- List<String> c = refMgr.findUncreated();
+ List<WikiPath> c = refMgr.findUncreated();
assertTrue( "Non-existent reference not detected by ReferenceManager",
- Util.collectionContains( c, "Foobar" ));
+ c.contains( WikiPath.valueOf( "Foobar" ) ) );
Thread.sleep( 2000L ); // Wait two seconds for filesystem granularity
@@ -727,7 +727,7 @@
assertTrue( "Non-existent reference after external page change " +
"not detected by ReferenceManager",
- Util.collectionContains( c, "Puppaa" ));
+ c.contains( WikiPath.valueOf( "Puppaa" ) ) );
}
@@ -742,9 +742,9 @@
m_engine.saveText( NAME1, "[Foobar]" );
m_engine.getText( NAME1 ); // Ensure that page is cached.
- List<String> c = refMgr.findUncreated();
+ List<WikiPath> c = refMgr.findUncreated();
assertEquals( "uncreated count", 1, c.size() );
- assertEquals( "wrong referenced page", "Foobar",
(String)c.iterator().next() );
+ assertEquals( "wrong referenced page", WikiPath.valueOf( "Foobar" ),
c.iterator().next() );
Thread.sleep( 2000L ); // Wait two seconds for filesystem granularity