Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 8f124818 authored by Alan Viverette's avatar Alan Viverette
Browse files

Clear stack trace from re-thrown inflater exceptions

We don't need intermediate stack traces for re-thrown inflater
exceptions. Yes, we care that you failed to inflate some class.
No, we don't care how many times you recursed in LayoutInflater
before you got there.

Change-Id: Ie9bba7cebab6cdf73ceead49f080dcf23e0a9f25
parent a5940f8d
Loading
Loading
Loading
Loading
+25 −26
Original line number Original line Diff line number Diff line
@@ -72,6 +72,9 @@ public abstract class LayoutInflater {
    private static final String TAG = LayoutInflater.class.getSimpleName();
    private static final String TAG = LayoutInflater.class.getSimpleName();
    private static final boolean DEBUG = false;
    private static final boolean DEBUG = false;


    /** Empty stack trace used to avoid log spam in re-throw exceptions. */
    private static final StackTraceElement[] EMPTY_STACK_TRACE = new StackTraceElement[0];

    /**
    /**
     * This field should be made private, so it is hidden from the SDK.
     * This field should be made private, so it is hidden from the SDK.
     * {@hide}
     * {@hide}
@@ -532,15 +535,14 @@ public abstract class LayoutInflater {
                }
                }


            } catch (XmlPullParserException e) {
            } catch (XmlPullParserException e) {
                InflateException ex = new InflateException(e.getMessage());
                final InflateException ie = new InflateException(e.getMessage(), e);
                ex.initCause(e);
                ie.setStackTrace(EMPTY_STACK_TRACE);
                throw ex;
                throw ie;
            } catch (Exception e) {
            } catch (Exception e) {
                InflateException ex = new InflateException(
                final InflateException ie = new InflateException(parser.getPositionDescription()
                        parser.getPositionDescription()
                        + ": " + e.getMessage(), e);
                                + ": " + e.getMessage());
                ie.setStackTrace(EMPTY_STACK_TRACE);
                ex.initCause(e);
                throw ie;
                throw ex;
            } finally {
            } finally {
                // Don't retain static reference on context.
                // Don't retain static reference on context.
                mConstructorArgs[0] = lastContext;
                mConstructorArgs[0] = lastContext;
@@ -625,27 +627,25 @@ public abstract class LayoutInflater {
            return view;
            return view;


        } catch (NoSuchMethodException e) {
        } catch (NoSuchMethodException e) {
            InflateException ie = new InflateException(attrs.getPositionDescription()
            final InflateException ie = new InflateException(attrs.getPositionDescription()
                    + ": Error inflating class "
                    + ": Error inflating class " + (prefix != null ? (prefix + name) : name), e);
                    + (prefix != null ? (prefix + name) : name));
            ie.setStackTrace(EMPTY_STACK_TRACE);
            ie.initCause(e);
            throw ie;
            throw ie;


        } catch (ClassCastException e) {
        } catch (ClassCastException e) {
            // If loaded class is not a View subclass
            // If loaded class is not a View subclass
            InflateException ie = new InflateException(attrs.getPositionDescription()
            final InflateException ie = new InflateException(attrs.getPositionDescription()
                    + ": Class is not a View "
                    + ": Class is not a View " + (prefix != null ? (prefix + name) : name), e);
                    + (prefix != null ? (prefix + name) : name));
            ie.setStackTrace(EMPTY_STACK_TRACE);
            ie.initCause(e);
            throw ie;
            throw ie;
        } catch (ClassNotFoundException e) {
        } catch (ClassNotFoundException e) {
            // If loadClass fails, we should propagate the exception.
            // If loadClass fails, we should propagate the exception.
            throw e;
            throw e;
        } catch (Exception e) {
        } catch (Exception e) {
            InflateException ie = new InflateException(attrs.getPositionDescription()
            final InflateException ie = new InflateException(
                    + ": Error inflating class "
                    attrs.getPositionDescription() + ": Error inflating class "
                    + (clazz == null ? "<unknown>" : clazz.getName()));
                            + (clazz == null ? "<unknown>" : clazz.getName()), e);
            ie.initCause(e);
            ie.setStackTrace(EMPTY_STACK_TRACE);
            throw ie;
            throw ie;
        } finally {
        } finally {
            Trace.traceEnd(Trace.TRACE_TAG_VIEW);
            Trace.traceEnd(Trace.TRACE_TAG_VIEW);
@@ -657,8 +657,7 @@ public abstract class LayoutInflater {
     */
     */
    private void failNotAllowed(String name, String prefix, AttributeSet attrs) {
    private void failNotAllowed(String name, String prefix, AttributeSet attrs) {
        throw new InflateException(attrs.getPositionDescription()
        throw new InflateException(attrs.getPositionDescription()
                + ": Class not allowed to be inflated "
                + ": Class not allowed to be inflated "+ (prefix != null ? (prefix + name) : name));
                + (prefix != null ? (prefix + name) : name));
    }
    }


    /**
    /**
@@ -774,14 +773,14 @@ public abstract class LayoutInflater {


        } catch (ClassNotFoundException e) {
        } catch (ClassNotFoundException e) {
            final InflateException ie = new InflateException(attrs.getPositionDescription()
            final InflateException ie = new InflateException(attrs.getPositionDescription()
                    + ": Error inflating class " + name);
                    + ": Error inflating class " + name, e);
            ie.initCause(e);
            ie.setStackTrace(EMPTY_STACK_TRACE);
            throw ie;
            throw ie;


        } catch (Exception e) {
        } catch (Exception e) {
            final InflateException ie = new InflateException(attrs.getPositionDescription()
            final InflateException ie = new InflateException(attrs.getPositionDescription()
                    + ": Error inflating class " + name);
                    + ": Error inflating class " + name, e);
            ie.initCause(e);
            ie.setStackTrace(EMPTY_STACK_TRACE);
            throw ie;
            throw ie;
        }
        }
    }
    }