1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package org.xwiki.job.internal.xstream

File SafeTreeUnmarshaller.java

 

Coverage histogram

../../../../../img/srcFileCovDistChart10.png
0% of files have more coverage

Code metrics

0
10
2
1
81
38
4
0.4
5
2
2

Classes

Class Line # Actions
SafeTreeUnmarshaller 40 10 0% 4 1
0.916666791.7%
 

Contributing tests

This file is covered by 36 tests. .

Source view

1    /*
2    * See the NOTICE file distributed with this work for additional
3    * information regarding copyright ownership.
4    *
5    * This is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU Lesser General Public License as
7    * published by the Free Software Foundation; either version 2.1 of
8    * the License, or (at your option) any later version.
9    *
10    * This software is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13    * Lesser General Public License for more details.
14    *
15    * You should have received a copy of the GNU Lesser General Public
16    * License along with this software; if not, write to the Free
17    * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18    * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
19    */
20    package org.xwiki.job.internal.xstream;
21   
22    import org.apache.commons.lang3.reflect.FieldUtils;
23    import org.slf4j.Logger;
24    import org.slf4j.LoggerFactory;
25   
26    import com.thoughtworks.xstream.converters.Converter;
27    import com.thoughtworks.xstream.converters.ConverterLookup;
28    import com.thoughtworks.xstream.core.ReferenceByXPathUnmarshaller;
29    import com.thoughtworks.xstream.core.TreeUnmarshaller;
30    import com.thoughtworks.xstream.core.util.FastStack;
31    import com.thoughtworks.xstream.io.HierarchicalStreamReader;
32    import com.thoughtworks.xstream.mapper.Mapper;
33   
34    /**
35    * A {@link ReferenceByXPathUnmarshaller} which never fail whatever value is provided.
36    *
37    * @version $Id: 7c75f16af32b6e83c7f9be765eacef68517888f3 $
38    * @since 5.0M2
39    */
 
40    public class SafeTreeUnmarshaller extends ReferenceByXPathUnmarshaller
41    {
42    /**
43    * The logger.
44    */
45    private static final Logger LOGGER = LoggerFactory.getLogger(SafeTreeUnmarshaller.class);
46   
47    /**
48    * @see TreeUnmarshaller#TreeUnmarshaller(Object, HierarchicalStreamReader, ConverterLookup, Mapper).
49    * @param root the root object
50    * @param reader the reader
51    * @param converterLookup the converter lookup
52    * @param mapper the mapper
53    */
 
54  66 toggle public SafeTreeUnmarshaller(Object root, HierarchicalStreamReader reader, ConverterLookup converterLookup,
55    Mapper mapper)
56    {
57  66 super(root, reader, converterLookup, mapper);
58    }
59   
 
60  1971 toggle @Override
61    protected Object convert(Object parent, Class type, Converter converter)
62    {
63  1971 try {
64  1971 return super.convert(parent, type, converter);
65    } catch (Throwable e) {
66  8 FastStack types;
67  8 try {
68  8 types = (FastStack) FieldUtils.getDeclaredField(TreeUnmarshaller.class, "types", true).get(this);
69  8 types.popSilently();
70    } catch (Exception e1) {
71    // Should never happen
72  0 LOGGER.debug("Failed to access private field com.thoughtworks.xstream.core.TreeUnmarshaller#types",
73    type, e1);
74    }
75   
76  8 LOGGER.debug("Got unknown exception when converting object of type [{}]", type, e);
77    }
78   
79  8 return null;
80    }
81    }