public static void main(String[] args) {
   int errorCount = 0;
   for (int i = 0; i < NTESTS; i++) {
     try {
       System.out.println("Test " + i + ":");
       test(i);
     } catch (Throwable e) {
       errorCount++;
       boolean first = true;
       do {
         System.err.println(first ? "Exception:" : "Caused by:");
         first = false;
         e.printStackTrace();
         Throwable nexte;
         nexte = e.getCause();
         if (nexte == null) { // old JMX
           if (e instanceof MBeanException) nexte = ((MBeanException) e).getTargetException();
         }
         e = nexte;
       } while (e != null);
     }
   }
   if (errorCount == 0) {
     System.out.println("All ModelMBean tests successfuly passed");
     System.out.println("Bye! Bye!");
     // JTReg doesn't like System.exit(0);
     return;
   } else {
     System.err.println("ERROR: " + errorCount + " tests failed");
     System.exit(errorCount);
   }
 }
Example #2
0
  /**
   * Called to process events. Mouse events will be rewritten to indicate the position in the
   * document clicked, instead of the position of the panel.
   *
   * @param event to process.
   */
  protected void processEvent(AWTEvent event) {
    try {
      if (event instanceof MouseEvent) {
        final Point scrollPosition = getScrollPosition();

        if (scrollPosition != null) {
          final MouseEvent mouseEvent = (MouseEvent) event;
          event =
              new MouseEvent(
                  (Component) mouseEvent.getSource(),
                  mouseEvent.getID(),
                  mouseEvent.getWhen(),
                  mouseEvent.getModifiers(),
                  mouseEvent.getX() + scrollPosition.x,
                  mouseEvent.getY() + scrollPosition.y,
                  mouseEvent.getClickCount(),
                  mouseEvent.isPopupTrigger());
        }
      }
    } catch (final Throwable exp) {
      exp.printStackTrace(DjVuOptions.err);
      System.gc();
    }

    super.processEvent(event);
  }
Example #3
0
  public static final void fireEvent(GenericEvent e, Method m, Vector listeners)
      throws PropertyVetoException {
    Object[] snapshot = null;

    synchronized (listeners) {
      snapshot = new Object[listeners.size()];
      listeners.copyInto(snapshot);
    }

    // leighd 04/14/99 - modified for event debugging
    if (gDebugEvents) Engine.debugLog("Event : " + e.toString());

    Object params[] = new Object[] {e};

    for (int i = 0; i < snapshot.length; i++) {
      if ((e instanceof Consumable) && ((Consumable) e).isConsumed()) {
        // leighd 04/14/99
        // note that we don't catch the consumption of the
        // event until we've passed through the loop again,
        // so we reference i-1
        if (gDebugEvents) Engine.debugLog("Consumed By : " + snapshot[i - 1]);
        return;
      }
      try {
        m.invoke(snapshot[i], params);
      } catch (IllegalAccessException iae) {
        iae.printStackTrace();
      } catch (InvocationTargetException ite) {
        Throwable t = ite.getTargetException();
        if (t instanceof PropertyVetoException) throw ((PropertyVetoException) t);
        else t.printStackTrace();
      }
    }
  }
Example #4
0
 public static LispObject evaluate(String name, Environment environment, List<LispObject> args) {
   for (Class c : getSubroutineContainers()) {
     for (Method m : c.getMethods()) {
       Subroutine annotation = m.getAnnotation(Subroutine.class);
       if (annotation == null || !annotation.value().equals(name)) continue;
       if (!Arrays.asList(mySpecialForms).contains(c)) {
         if (!environment.areArgumentsEvaluated()) {
           for (int i = 0, dataSize = args.size(); i < dataSize; i++) {
             args.set(i, args.get(i).evaluate(environment));
           }
         } else {
           environment.setArgumentsEvaluated(false);
         }
       }
       ArgumentsList arguments = parseArguments(m, environment, args);
       checkArguments(name, arguments, args);
       try {
         return (LispObject) m.invoke(null, arguments.getValues());
       } catch (IllegalAccessException | InvocationTargetException e) {
         if (e.getCause().getMessage() == null) e.getCause().printStackTrace();
         else System.err.println(e.getCause().getMessage());
         Throwable cause = getCause(e);
         if (cause instanceof LispThrow) throw (LispThrow) cause;
         if (cause instanceof VoidVariableException && TestMode.TEST && c == Key.class) {
           System.err.println("Skip keymap errors in test mode");
           return LispSymbol.ourNil;
         }
         if (cause instanceof LispException) throw (LispException) cause;
         cause.printStackTrace();
         throw new LispException(e.getCause().getMessage());
       }
     }
   }
   throw new InternalException(JelispBundle.message("unknown.subroutine", name));
 }
Example #5
0
 Object createGuiElement(Class cls, EntityPlayer player, World world, int x, int y, int z) {
   try {
     try {
       if (debugGui)
         System.out.printf(
             "BaseMod.createGuiElement: Invoking create method of %s for %s in %s\n",
             cls, player, world);
       return cls.getMethod(
               "create", EntityPlayer.class, World.class, int.class, int.class, int.class)
           .invoke(null, player, world, x, y, z);
     } catch (NoSuchMethodException e) {
       if (debugGui)
         System.out.printf("BaseMod.createGuiElement: Invoking constructor of %s\n", cls);
       return cls.getConstructor(EntityPlayer.class, World.class, int.class, int.class, int.class)
           .newInstance(player, world, x, y, z);
     }
   } catch (Exception e) {
     Throwable cause = e.getCause();
     System.out.printf("BaseMod.createGuiElement: %s: %s\n", e, cause);
     if (cause != null) cause.printStackTrace();
     else e.printStackTrace();
     // throw new RuntimeException(e);
     return null;
   }
 }
Example #6
0
 /**
  * If <code>getUI()</code> fails for any reason, it calls this method before returning <code>null
  * </code>. Subclasses may choose to do more or less here.
  *
  * @param msg message string to print
  * @see #getUI
  */
 protected void getUIError(String msg) {
   System.err.println("UIDefaults.getUI() failed: " + msg);
   try {
     throw new Error();
   } catch (Throwable e) {
     e.printStackTrace();
   }
 }
Example #7
0
  public static void premain(String args, Instrumentation inst) throws Exception {
    try {
      String[] agentArgs;
      if (args == null) agentArgs = new String[] {""};
      else agentArgs = args.split(",");
      if (!agentArgs[0].equals("instrumenting")) jarFileName = agentArgs[0];
      BaseClassTransformer rct = null;
      rct = new BaseClassTransformer();
      if (agentArgs[0].equals("instrumenting")) {
        initVMClasses = new HashSet<String>();
        for (Class<?> c : inst.getAllLoadedClasses()) {
          ((Set<String>) initVMClasses).add(c.getName());
        }
      }
      if (!agentArgs[0].equals("instrumenting")) {

        inst.addTransformer(rct);
        Tracer.setLocals(new CounterThreadLocal());
        Tracer.overrideAll(true);
        for (Class<?> c : inst.getAllLoadedClasses()) {
          try {
            if (c.isInterface()) continue;
            if (c.isArray()) continue;
            byte[] bytes = rct.getBytes(c.getName());
            if (bytes == null) {
              continue;
            }
            inst.redefineClasses(new ClassDefinition[] {new ClassDefinition(c, bytes)});
          } catch (Throwable e) {
            synchronized (System.err) {
              System.err.println("" + c + " failed...");
              e.printStackTrace();
            }
          }
        }
        Runtime.getRuntime()
            .addShutdownHook(
                new Thread() {
                  public void run() {
                    Tracer.mark();
                    try {
                      PrintStream ps = new PrintStream("bailout.txt");
                      ps.println("Bailouts: " + Tracer.getBailoutCount());
                      ps.close();
                    } catch (Exception e) {
                    }
                    Tracer.unmark();
                  }
                });
        if ("true".equals(System.getProperty("bci.observerOn"))) Tracer.overrideAll(false);
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
Example #8
0
 /**
  * Called to process scrollbar events.
  *
  * @param event to process.
  */
 public void adjustmentValueChanged(AdjustmentEvent event) {
   try {
     final Scrollbar hScroll = getScrollbar(Scrollbar.HORIZONTAL);
     final Scrollbar vScroll = getScrollbar(Scrollbar.VERTICAL);
     final Point scrollPosition = getScrollPosition();
     setScrollPosition(
         (hScroll != null) ? hScroll.getValue() : scrollPosition.x,
         (vScroll != null) ? vScroll.getValue() : scrollPosition.y);
   } catch (final Throwable exp) {
     exp.printStackTrace(DjVuOptions.err);
     System.gc();
   }
 }
Example #9
0
 public static IInventory getInv(VAnvil anvil, String name)
 {
     try
     {
         Field f = ContainerAnvil.class.getDeclaredField(name);
         f.setAccessible(true);
         return (IInventory)f.get(anvil);
     }
     catch(Throwable t)
     {
         t.printStackTrace();
         return null;
     }
 }
Example #10
0
 /**
  * Try to execute given method on given object. Handles invocation target exceptions. XXX nearly
  * duplicates tryMethod in JGEngine.
  *
  * @return null means method does not exist or returned null/void
  */
 static Object tryMethod(Object o, String name, Object[] args) {
   try {
     Method met = JREEngine.getMethod(o.getClass(), name, args);
     if (met == null) return null;
     return met.invoke(o, args);
   } catch (InvocationTargetException ex) {
     Throwable ex_t = ex.getTargetException();
     ex_t.printStackTrace();
     return null;
   } catch (IllegalAccessException ex) {
     System.err.println("Unexpected exception:");
     ex.printStackTrace();
     return null;
   }
 }
Example #11
0
  public static boolean exec(String cmd) throws Exception {
    int exitVal = -1;
    try {
      Runtime rt = Runtime.getRuntime();
      Process proc = rt.exec(new String[] {"/bin/bash", "-c", cmd});

      OutputHandler err = new OutputHandler(proc.getErrorStream(), cmd);
      err.start();

      OutputHandler out = new OutputHandler(proc.getInputStream(), cmd);
      out.start();

      exitVal = proc.waitFor();

    } catch (Throwable t) {
      t.printStackTrace();
    }
    return (exitVal == 0);
  }
Example #12
0
 public VAnvil(EntityPlayer entityplayer)
 {
     super(entityplayer.inventory, null, 0, 0, 0, entityplayer);
     checkReachable = false;
     _player = entityplayer;
     for(int i = 0; i < #FIELD_CONTAINER_3#.size(); i++)
     {
         try
         {
             if(Class.forName("net.minecraft.server.v#MC_VERSION#.SlotAnvilResult").isInstance(#FIELD_CONTAINER_3#.get(i)))
             {
                 #FIELD_CONTAINER_3#.set(i, new VAnvilSlot(this, getInv("#FIELD_CONTAINERANVIL_2#"), 2, 134, 47));
                 break;
             }
         }
         catch(Throwable t)
         {
             t.printStackTrace();
             break;
         }
     }
 }
Example #13
0
  /**
   * Fire an event to the registered listeners, but stop on a PropertyVetoException. Subclasses may
   * choose to implement their own fire method, and just use this class for the add/remove methods.
   *
   * @param evt the Event we're going to pass to the listeners
   * @throws java.beans.PropertyVetoException
   */
  protected final void firePropertyEvent(Object evt, Method m) throws PropertyVetoException {
    // grab a reference to the listeners
    Object[] array = fListeners;

    if (array.length == 0) return;

    Object[] params = fCachedParams;
    if (params == null) params = new Object[] {evt}; // wasn't available, make a new array
    else {
      fCachedParams = null; // set to null in case fire is called re-entrantly
      params[0] = evt;
    }

    try {
      for (int i = 0; i < array.length; i++) {
        try {
          m.invoke(array[i], params);
        } catch (IllegalAccessException iae) {
          iae.printStackTrace();
        } catch (InvocationTargetException ite) {
          Throwable t = ite.getTargetException();
          if (t instanceof PropertyVetoException) throw ((PropertyVetoException) t);
          else t.printStackTrace();
        }

        if ((evt instanceof Consumable) && ((Consumable) evt).isConsumed()) {
          if (gDebugEvents) Engine.debugLog("Consumed By : " + array[i]);
          return;
        }
      }
    } finally {
      // make our param array available for re-use
      // doesn't matter if we made it fresh, or already
      // reused it from a previous fire call
      params[0] = null;
      fCachedParams = params;
    }
  }
Example #14
0
 static void unexpected(Throwable t) {
   failed++;
   t.printStackTrace();
 }
Example #15
0
 private void handleException(Throwable ex) {
   ex.printStackTrace();
   JOptionPane.showMessageDialog(
       this, ex.toString(), ex.getClass().getName(), JOptionPane.ERROR_MESSAGE);
 }
Example #16
0
  // Information needed to get a single file:
  // BASE_PATH, FILE_ID, TIMESTAMP_START, TIMESTAMP_STOP, SOURCE, FILESYSTEM
  private static Vector<Path> getFile(
      FileSystem fs, Hashtable<String, String> config, dbutil db_util) throws Exception {
    Long latestVersion = latestVersion(config, db_util);

    try {
      config.put("timestamp_start", config.get("timestamp_start"));
      config.put("timestamp_real", latestVersion.toString());
      config.put("timestamp_stop", latestVersion.toString());
    } catch (Exception E) {
      logger.error("Tryign to get file that is impossible to generate: " + getFullPath(config));
      return null;
    }
    if (Integer.parseInt(config.get("timestamp_start"))
        > Integer.parseInt(config.get("timestamp_stop"))) {
      return null;
    }
    logger.debug(
        "Getting DB for timestamp "
            + config.get("timestamp_start")
            + " to "
            + config.get("timestamp_stop"));

    String final_result = getFullPath(config);

    String temp_path_base =
        config.get("local_temp_path")
            + "_"
            + config.get("task_id")
            + "_"
            + config.get("run_id")
            + "/";
    Path newPath = new Path(final_result + "*");
    Vector<Path> ret_path = new Vector<Path>();
    String lockName = lock(final_result.replaceAll("/", "_"));
    if (fs.globStatus(newPath).length != 0) {
      ret_path.add(newPath);
      unlock(lockName);
      config.put("full_file_name", final_result);
      return ret_path;
    } else {
      if (!config.get("source").equals("local")) {
        config.put("temp_path_base", temp_path_base);

        config.put("timestamp_start", config.get("timestamp_start"));
        config.put("timestamp_real", latestVersion.toString());
        config.put("timestamp_stop", latestVersion.toString());

        Class<?> sourceClass =
            Class.forName("org.gestore.plugin.source." + config.get("source") + "Source");
        Method process_data = sourceClass.getMethod("process", Hashtable.class, FileSystem.class);
        Object processor = sourceClass.newInstance();
        Object retVal;
        try {
          retVal = process_data.invoke(processor, config, fs);
        } catch (InvocationTargetException E) {
          Throwable exception = E.getTargetException();
          logger.error("Unable to call method in child class: " + exception.toString());
          exception.printStackTrace(System.out);
          unlock(lockName);
          return null;
        }
        FileStatus[] files = (FileStatus[]) retVal;
        if (files == null) {
          logger.error("Error getting files, no files returned");
          return null;
        }

        for (FileStatus file : files) {
          Path cur_file = file.getPath();
          Path cur_local_path = new Path(temp_path_base + config.get("file_id"));
          String suffix = getSuffix(config.get("file_id"), cur_file.getName());
          cur_local_path = cur_local_path.suffix(suffix);
          Path res_path = new Path(new String(final_result + suffix));
          logger.debug("Moving file" + cur_file.toString() + " to " + res_path.toString());
          if (config.get("copy").equals("true")) {
            fs.moveFromLocalFile(cur_file, res_path);
          } else {
            fs.rename(cur_file, res_path);
          }
        }

        config.put("full_file_name", final_result);
      }
    }
    unlock(lockName);
    return ret_path;
  }