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

File SafeThrowableConverter.java

 

Coverage histogram

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

Code metrics

0
8
4
1
80
37
4
0.5
2
4
1

Classes

Class Line # Actions
SafeThrowableConverter 36 8 0% 4 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 com.thoughtworks.xstream.converters.Converter;
23    import com.thoughtworks.xstream.converters.MarshallingContext;
24    import com.thoughtworks.xstream.converters.UnmarshallingContext;
25    import com.thoughtworks.xstream.io.HierarchicalStreamReader;
26    import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
27    import com.thoughtworks.xstream.mapper.Mapper;
28   
29    /**
30    * Make sure to serialize on {@link Throwable} fields skip any custom field that might make XStream try to serialize the
31    * world.
32    *
33    * @version $Id: cfe45715627c6712cfea2c68350d72169c46fd47 $
34    * @since 8.4RC1
35    */
 
36    public class SafeThrowableConverter implements Converter
37    {
38    private final Mapper mapper;
39   
40    private final Converter objectConverter;
41   
42    /**
43    * @param mapper the mapper used to convert other values
44    * @param objectConverter the {@link Converter} for {@link Object} type
45    */
 
46  553 toggle public SafeThrowableConverter(Mapper mapper, Converter objectConverter)
47    {
48  553 this.mapper = mapper;
49  553 this.objectConverter = objectConverter;
50    }
51   
 
52  2232 toggle @Override
53    public boolean canConvert(final Class type)
54    {
55  2235 return Throwable.class.isAssignableFrom(type);
56    }
57   
 
58  24 toggle @Override
59    public void marshal(Object source, HierarchicalStreamWriter writer, MarshallingContext context)
60    {
61  24 Throwable throwable = (Throwable) source;
62   
63    // Message
64  24 XStreamUtils.serializeField("detailMessage", String.class, throwable.getMessage(), writer, context,
65    this.mapper);
66   
67    // Cause
68  24 XStreamUtils.serializeField("cause", Throwable.class, throwable.getCause(), writer, context, this.mapper);
69   
70    // Stack trace
71  24 XStreamUtils.serializeField("stackTrace", StackTraceElement[].class, throwable.getStackTrace(), writer, context,
72    this.mapper);
73    }
74   
 
75  2 toggle @Override
76    public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context)
77    {
78  2 return this.objectConverter.unmarshal(reader, context);
79    }
80    }