@Test public void testUninterpretThrowsNegativeArraySizeException() throws Throwable { byte[] rawData = new byte[1]; try { new AsciiHexInterpreter().uninterpret(rawData, 100, -1); fail("Expected NegativeArraySizeException to be thrown"); } catch (NegativeArraySizeException ex) { assertNull("ex.getMessage()", ex.getMessage()); } }
/** When a negative capacity is used, a {@link NegativeArraySizeException} should be thrown. */ @Test public void testNegativeArraySizeException() { BooleanBag bag = new BooleanBag(); for (int i = 0; i < 32; i++) { try { bag.ensureCapacity(-(1 << i)); } catch (NegativeArraySizeException ex) { if (ex.getClass() == NegativeArraySizeException.class) continue; } fail("NegativeArraySizeException expected for capacity " + (-(1 << i))); } }
public static void main(String args[]) { try { int t[]; System.out.print("taille voulue : "); int n = Clavier.lireInt(); t = new int[n]; System.out.print("indice : "); int i = Clavier.lireInt(); t[i] = 12; System.out.println("*** fin normale"); } catch (NegativeArraySizeException e) { System.out.println("Exception taille tableau negative : " + e.getMessage()); } catch (ArrayIndexOutOfBoundsException e) { System.out.println("Exception indice tableau : " + e.getMessage()); } }
public static void main(String[] args) { int[] whee = new int[5]; try { Blah testBlah = new Blah(); testBlah.xxx().toString(); } catch (NullPointerException e) { System.out.println("NullPointerException message: " + e.getMessage()); e.printStackTrace(); System.out.println("------------------------"); System.out.println(); } try { int[] whee2 = new int[-2]; } catch (NegativeArraySizeException e) { System.out.println("NegativeArraySizeException message: " + e.getMessage()); e.printStackTrace(); System.out.println("------------------------"); System.out.println(); } try { whee[9] = 3; } catch (IndexOutOfBoundsException e) { System.out.println("IndexOutOfBoundsException message: " + e.getMessage()); e.printStackTrace(); System.out.println("------------------------"); System.out.println(); } try { divide(whee, 10); } catch (MyException e) { System.out.println("Custom message: " + e.getMessage()); } try { divide(whee, -2); } catch (MyException e) { System.out.println("Custom message: " + e.getMessage()); } }
public static void main(String[] args) { try { Bouquet bouquet = new Bouquet(-1); } catch (NegativeArraySizeException e) { System.out.println(e.getMessage()); } try { Bouquet bouquet = new Bouquet(4); } catch (IllegalStateException e) { System.out.println(e.getMessage()); } try { Bouquet bouquet = new Bouquet(5); System.out.println("It is not an exception."); } catch (Exception e) { System.out.println(e.getMessage()); } }
public Object getComponentArray(CallContext callcontext) { if (this.getComponentType() == null) return this; if (componentArray == null) { synchronized (lock) { if (componentArray == null) { // if (this.size() > 0) { if (this.componentType.equalsIgnoreCase(Pro.COMPONENT_BEAN)) { Class enumType = this.pros[0].getBeanClass(); // componentArray = new ArrayList(this.size()); componentArray = Array.newInstance(enumType, this .size()); int i = 0; if(pros != null) { Context currentLoopContext = callcontext != null?callcontext.getLoopContext():null; for (Pro v : this.pros) { try{ Array.set(componentArray, i, v.getBean(callcontext)); } finally { if(callcontext != null) callcontext.setLoopContext(currentLoopContext); } i++; } } } else if (this.componentType .equalsIgnoreCase(Pro.COMPONENT_STRING_SHORTNAME) || this.componentType .equalsIgnoreCase(Pro.COMPONENT_STRING)) { // componentArray = new ArrayList(this.size()); componentArray = Array.newInstance(String.class, this.size()); int i = 0; if(pros != null) { for (Pro v : this.pros) { Array.set(componentArray, i, v.getString()); i++; } } } else if (this.componentType.equalsIgnoreCase(Pro.COMPONENT_OBJECT_SHORTNAME) || this.componentType.equalsIgnoreCase(Pro.COMPONENT_OBJECT)) { // componentArray = new ArrayList(this.size()); componentArray = Array.newInstance(Object.class, this .size()); int i = 0; if(pros != null) { Context currentLoopContext = callcontext != null?callcontext.getLoopContext():null; for (Pro v : this.pros) { try{ Array.set(componentArray, i, v.getBean(callcontext)); } finally { if(callcontext != null) callcontext.setLoopContext(currentLoopContext); } i++; } } } else if (this.componentType.equalsIgnoreCase(Pro.COMPONENT_CLASS) ) { // componentArray = new ArrayList(this.size()); componentArray = Array.newInstance(Class.class, this .size()); int i = 0; if(pros != null) { Context currentLoopContext = callcontext != null?callcontext.getLoopContext():null; for (Pro v : this.pros) { try{ Object value = v.getBean(callcontext); Array.set(componentArray, i, ValueObjectUtil.typeCast(value, Class.class)); } finally { if(callcontext != null) callcontext.setLoopContext(currentLoopContext); } i++; } } } else { try { componentArray = Array.newInstance(ValueObjectUtil.getClass(componentType), this .size()); int i = 0; if(pros != null) { Context currentLoopContext = callcontext != null?callcontext.getLoopContext():null; for (Pro v : this.pros) { try{ Array.set(componentArray, i, v.getBean(callcontext)); } finally { if(callcontext != null) callcontext.setLoopContext(currentLoopContext); } i++; } } } catch (NegativeArraySizeException e) { log.error(e.getMessage(),e); componentArray = this; } catch (ClassNotFoundException e) { log.error(e.getMessage(),e); componentArray = this; } catch (Exception e) { log.error(e.getMessage(),e); componentArray = this; } } } // else { // componentArray = this; // } } } } return componentArray; }