Skip to content
Snippets Groups Projects
Commit feaf4165 authored by buczekp's avatar buczekp
Browse files

[LMS-1767] improved escaping of sets and handling of errors

SVN: 18755
parent 53331d4b
No related branches found
No related tags found
No related merge requests found
/*
* Copyright 2010 ETH Zuerich, CISD
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ch.systemsx.cisd.common.utilities;
import org.apache.log4j.Logger;
/**
* @author Piotr Buczek
*/
public class LogUtils
{
/** log error in production, fail in development mode */
public static void logErrorWithFailingAssertion(Logger logger, String message)
{
logger.error(message);
assert false : message;
}
}
......@@ -59,9 +59,11 @@ public class ReflectingStringEscaper
ReflectingStringEscaperUnrestricted<T> escaper =
new ReflectingStringEscaperUnrestricted<T>(true, bean);
return escaper.escape();
} catch (Exception exception)
} catch (Throwable t)
{
operationLog.error(exception.getMessage());
t.printStackTrace();
LogUtils.logErrorWithFailingAssertion(operationLog,
"Cannot traverse primitive collections or primitives " + t);
return null;
} finally
{
......
......@@ -22,6 +22,7 @@ import java.lang.reflect.Modifier;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
......@@ -81,7 +82,8 @@ class ReflectionStringTraverser
}
if (isMutable(object) == false)
{
log.error("Cannot traverse primitive collections or primitives " + object);
LogUtils.logErrorWithFailingAssertion(log,
"Cannot traverse primitive collections or primitives " + object);
return;
} else if (clazz.isArray())
{
......@@ -128,13 +130,13 @@ class ReflectionStringTraverser
try
{
traverseField(object, field);
} catch (Exception ex)
} catch (Throwable t)
{
log.error("Failed accessing field <" + field.getName() + "> of "
+ object.getClass() + ":\n\t" + object);
ex.printStackTrace();
throw new IllegalStateException("Should not happen: " + ex.getMessage());
t.printStackTrace();
LogUtils.logErrorWithFailingAssertion(
log,
"Failed accessing field <" + field.getName() + "> of "
+ object.getClass() + ":\n\t" + object);
}
}
}
......@@ -246,7 +248,8 @@ class ReflectionStringTraverser
} else
{
// NOTE: we do not handle e.g. list of list of Strings
log.error("Cannot traverse primitive collections or primitives " + collection);
LogUtils.logErrorWithFailingAssertion(log,
"Cannot traverse primitive collections or primitives " + collection);
}
}
}
......@@ -346,7 +349,7 @@ class ReflectionStringTraverser
return new ArrayList<T>();
} else if (Set.class.isAssignableFrom(clazz))
{
return new HashSet<T>();
return new LinkedHashSet<T>(); // preserve order
} else
{
throw new IllegalStateException("Do not know how to create a collection of type "
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment