Exemplo n.º 1
0
 private void appendStackTrace(Throwable exception, AstrixCallStackTrace trace) {
   Throwable lastThowableInChain = exception;
   while (lastThowableInChain.getCause() != null) {
     lastThowableInChain = lastThowableInChain.getCause();
   }
   lastThowableInChain.initCause(trace);
 }
Exemplo n.º 2
0
  /** {@inheritDoc} */
  @Override
  public void run() {

    while (requests != null) {

      /* Not processing a request. */
      currentRequest = null;

      /* Take a new request from the queue, waiting for one if none is available yet. */
      try {
        currentRequest = requests.take();
      }

      /* Interrupted? Well, try again! */
      catch (InterruptedException ignored) {
        continue;
      }

      /* Process the request. */
      try {
        ui.process(currentRequest.getRequest());
      }

      /* Uncaught exception occurred during the request. */
      catch (Throwable e) {
        e.initCause(currentRequest.getCause());
        logger.err(e, "Unexpected error occurred.");
      }
    }
  }
 private void addStack(IOException x, Set<Closeable> cs) {
   if (cs != null) {
     for (Closeable c : cs) {
       Throwable stack = c.stack;
       if (stack != null) {
         Throwable t = x;
         while (t.getCause() != null) {
           t = t.getCause();
         }
         t.initCause(stack);
       }
     }
   }
 }
Exemplo n.º 4
0
    public static void assertGC(String msg, String... names) {
      AssertionFailedError t = null;

      List<Reference> refs = new ArrayList<Reference>();
      List<String> txts = new ArrayList<String>();
      int count = 0;
      Set<String> nameSet =
          names == null || names.length == 0 ? null : new HashSet<String>(Arrays.asList(names));
      synchronized (instances) {
        for (Iterator<Map.Entry<Object, String>> it = instances.entrySet().iterator();
            it.hasNext(); ) {
          Entry<Object, String> entry = it.next();
          if (nameSet != null && !nameSet.contains(entry.getValue())) {
            continue;
          }

          refs.add(new WeakReference<Object>(entry.getKey()));
          txts.add(entry.getValue());
          it.remove();
          count++;
        }
      }

      if (count == 0) {
        Assert.fail("No instance of this type reported");
      }

      for (int i = 0; i < count; i++) {
        Reference<?> r = refs.get(i);
        try {
          NbTestCase.assertGC(msg + " " + txts.get(i), r);
        } catch (AssertionFailedError ex) {
          if (t == null) {
            t = ex;
          } else {
            Throwable last = t;
            while (last.getCause() != null) {
              last = last.getCause();
            }
            last.initCause(ex);
          }
        }
      }
      if (t != null) {
        throw t;
      }
    }
Exemplo n.º 5
0
 // recursively parse the causes and instantiate corresponding throwables
 private Throwable getCause(Iterator<String> linesIterator, String firstLine) {
   // The actual exception class of the cause might be unavailable at the
   // client -> use a standard throwable to represent the cause.
   Throwable res = new Throwable(firstLine.substring(firstLine.indexOf(":") + 2));
   List<StackTraceElement> stackTraceList = new ArrayList<StackTraceElement>();
   while (linesIterator.hasNext()) {
     String oneLine = linesIterator.next();
     if (oneLine.startsWith("Caused by:")) {
       Throwable nestedCause = getCause(linesIterator, oneLine);
       res.initCause(nestedCause);
       break;
     }
     stackTraceList.add(parseStackTrackLine(oneLine));
   }
   StackTraceElement[] stackTraceElement = new StackTraceElement[stackTraceList.size()];
   res.setStackTrace(stackTraceList.toArray(stackTraceElement));
   return res;
 }
 public void cancel(Throwable cause) {
   if (state == State.CREATED) {
     assert heirs.size() == 0;
     state = State.CLOSED;
     parent.remove(this);
     return;
   }
   if (failure == null) {
     canceled = true;
     failure = new CancellationException();
     if (stackTrace != null) {
       failure.setStackTrace(stackTrace.getStackTrace());
     }
     failure.initCause(cause);
     if (state == State.TRYING) {
       cancelHeirs();
     }
   }
 }
 protected Throwable looseUnmarsalThrowable(OpenWireFormat wireFormat, DataInput dataIn)
     throws IOException {
   if (dataIn.readBoolean()) {
     String clazz = looseUnmarshalString(dataIn);
     String message = looseUnmarshalString(dataIn);
     Throwable o = createThrowable(clazz, message);
     if (wireFormat.isStackTraceEnabled()) {
       if (STACK_TRACE_ELEMENT_CONSTRUCTOR != null) {
         StackTraceElement ss[] = new StackTraceElement[dataIn.readShort()];
         for (int i = 0; i < ss.length; i++) {
           try {
             ss[i] =
                 (StackTraceElement)
                     STACK_TRACE_ELEMENT_CONSTRUCTOR.newInstance(
                         new Object[] {
                           looseUnmarshalString(dataIn),
                           looseUnmarshalString(dataIn),
                           looseUnmarshalString(dataIn),
                           Integer.valueOf(dataIn.readInt())
                         });
           } catch (IOException e) {
             throw e;
           } catch (Throwable e) {
           }
         }
         o.setStackTrace(ss);
       } else {
         short size = dataIn.readShort();
         for (int i = 0; i < size; i++) {
           looseUnmarshalString(dataIn);
           looseUnmarshalString(dataIn);
           looseUnmarshalString(dataIn);
           dataIn.readInt();
         }
       }
       o.initCause(looseUnmarsalThrowable(wireFormat, dataIn));
     }
     return o;
   } else {
     return null;
   }
 }
Exemplo n.º 8
0
    public Throwable read(ClassLoader classLoader) throws IOException {
      final Throwable causeThrowable = getCause(classLoader);
      Throwable throwable = null;
      if (serializedException != null) {
        try {
          final ExceptionReplacingObjectInputStream ois =
              new ExceptionReplacingObjectInputStream(
                  new ByteArrayInputStream(serializedException), classLoader) {
                @Override
                protected Object resolveObject(Object obj) throws IOException {
                  if (obj instanceof CausePlaceholder) {
                    return causeThrowable;
                  }
                  return super.resolveObject(obj);
                }
              };
          throwable = (Throwable) ois.readObject();
        } catch (ClassNotFoundException e) {
          // Ignore
        } catch (InvalidClassException e) {
          try {
            Constructor<?> constructor = classLoader.loadClass(type).getConstructor(String.class);
            throwable = (Throwable) constructor.newInstance(message);
            throwable.initCause(causeThrowable);
            throwable.setStackTrace(stackTrace);
          } catch (ClassNotFoundException e1) {
            // Ignore
          } catch (NoSuchMethodException e1) {
            // Ignore
          } catch (Throwable t) {
            throw UncheckedException.throwAsUncheckedException(t);
          }
        }
      }

      if (throwable == null) {
        throwable = new PlaceholderException(type, message, causeThrowable);
        throwable.setStackTrace(stackTrace);
      }

      return throwable;
    }
Exemplo n.º 9
0
  private static Throwable toStackTrace(
      List<String> details, StackTraceElement[] parent, int index) {
    String detail = details.get(index++);
    if (!detail.startsWith("*")) {
      return null; // should not be happened. ignore remaining
    }
    int i1 = detail.indexOf(':');
    int i3 = detail.lastIndexOf(':');
    int i2 = detail.substring(0, i3).lastIndexOf(':');
    String exceptionClass = detail.substring(1, i1);
    String exceptionMessage = detail.substring(i1 + 1, i2);
    Throwable ex = newInstance(exceptionClass, exceptionMessage);

    int length = Integer.parseInt(detail.substring(i2 + 1, i3));
    int unique = Integer.parseInt(detail.substring(i3 + 1));

    int i = 0;
    StackTraceElement[] trace = new StackTraceElement[length];
    for (; i <= unique; i++) {
      detail = details.get(index++);
      int j1 = detail.indexOf(':');
      int j3 = detail.lastIndexOf(':');
      int j2 = detail.substring(0, j3).lastIndexOf(':');
      String className = detail.substring(0, j1);
      String methodName = detail.substring(j1 + 1, j2);
      String fileName = detail.substring(j2 + 1, j3);
      if (fileName.isEmpty()) {
        fileName = null;
      }
      int lineNumber = Integer.parseInt(detail.substring(j3 + 1));
      trace[i] = new StackTraceElement(className, methodName, fileName, lineNumber);
    }
    int common = trace.length - i;
    if (common > 0) {
      System.arraycopy(parent, parent.length - common, trace, trace.length - common, common);
    }
    if (details.size() > index) {
      ex.initCause(toStackTrace(details, trace, index));
    }
    ex.setStackTrace(trace);
    return ex;
  }
Exemplo n.º 10
0
  public static void rewriteBlameStackTrace(final Throwable innerBlame) {
    final StackTraceElement[] stackTrace = innerBlame.getStackTrace();

    final List<StackTraceElement> innerStackTrace = new ArrayList<StackTraceElement>(10);
    final List<StackTraceElement> outerStackTrace = new ArrayList<StackTraceElement>(10);
    for (final StackTraceElement el : stackTrace) {
      if (el.getClassName().startsWith("org.jboss.errai.codegen.")) {
        innerStackTrace.add(el);
      } else {
        outerStackTrace.add(el);
      }
    }

    innerBlame.setStackTrace(
        innerStackTrace.toArray(new StackTraceElement[innerStackTrace.size()]));

    final RuntimeException outerBlame = new RuntimeException("External call to API");
    outerBlame.setStackTrace(
        outerStackTrace.toArray(new StackTraceElement[outerStackTrace.size()]));
    innerBlame.initCause(outerBlame);
  }
 public Object invokeMethod(Object object, String methodName, Object[] arguments) {
   try {
     return delegate.invokeMethod(object, methodName, arguments);
   } catch (MissingMethodException mme) {
     // attempt builder resolution
     try {
       if (builder.getMetaClass().respondsTo(builder, methodName).isEmpty()) {
         // dispatch to factories if it is not a literal method
         return builder.invokeMethod(methodName, arguments);
       } else {
         return InvokerHelper.invokeMethod(builder, methodName, arguments);
       }
     } catch (MissingMethodException mme2) {
       // chain secondary exception
       Throwable root = mme;
       while (root.getCause() != null) {
         root = root.getCause();
       }
       root.initCause(mme2);
       // throw original
       throw mme;
     }
   }
 }
Exemplo n.º 12
0
Arquivo: F.java Projeto: gspandy/utils
 @Override
 public synchronized Throwable initCause(Throwable throwable) {
   return t.initCause(throwable);
 }