1. Project Clover database Sat Feb 2 2019 06:45:20 CET
  2. Package org.xwiki.job.internal.xstream

File SafeArrayConverter.java

 

Coverage histogram

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

Code metrics

2
16
4
1
92
50
7
0.44
4
4
1.75

Classes

Class Line # Actions
SafeArrayConverter 37 16 0% 7 0
1.0100%
 

Contributing tests

This file is covered by 209 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.slf4j.Logger;
23    import org.slf4j.LoggerFactory;
24   
25    import com.thoughtworks.xstream.converters.MarshallingContext;
26    import com.thoughtworks.xstream.converters.UnmarshallingContext;
27    import com.thoughtworks.xstream.converters.collections.ArrayConverter;
28    import com.thoughtworks.xstream.io.HierarchicalStreamReader;
29    import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
30   
31    /**
32    * A {@link ArrayConverter} which never fail whatever value is provided.
33    *
34    * @version $Id: 9f34d748373fef125e6cf20531ec52db8276a307 $
35    * @since 4.3M1
36    */
 
37    public class SafeArrayConverter extends ArrayConverter
38    {
39    /**
40    * The logger.
41    */
42    private static final Logger LOGGER = LoggerFactory.getLogger(SafeArrayConverter.class);
43   
44    /**
45    * @param xstream the {@link com.thoughtworks.xstream.XStream} instance to use to isolate array element marshaling
46    */
 
47  1659 toggle public SafeArrayConverter(SafeXStream xstream)
48    {
49  1659 super(xstream.getMapper());
50    }
51   
 
52  2645 toggle @Override
53    public boolean canConvert(Class type)
54    {
55  2650 return type == Object[].class;
56    }
57   
 
58  169 toggle @Override
59    protected Object readBareItem(HierarchicalStreamReader reader, UnmarshallingContext context, Object current)
60    {
61  169 Object value;
62  169 try {
63  169 value = super.readBareItem(reader, context, current);
64    } catch (Throwable e) {
65  8 LOGGER.debug("Failed to read field", e);
66   
67  8 value = null;
68    }
69   
70  169 return value;
71    }
72   
 
73  11934 toggle @Override
74    protected void writeCompleteItem(Object item, MarshallingContext context, HierarchicalStreamWriter writer)
75    {
76  11934 if (XStreamUtils.isSerializable(item)) {
77  11932 super.writeCompleteItem(item, context, writer);
78    } else {
79  2 String str;
80  2 try {
81  2 str = item.toString();
82    } catch (Throwable e) {
83  1 LOGGER.debug("Failed to convert item [{}] to String",
84    item.getClass().getName() + "@" + Integer.toHexString(System.identityHashCode(item)), e);
85   
86  1 str = null;
87    }
88   
89  2 super.writeCompleteItem(str, context, writer);
90    }
91    }
92    }