Tabnine Logo
IllegalArgumentException
Code IndexAdd Tabnine to your IDE (free)

How to use
IllegalArgumentException
in
java.lang

Best Java code snippets using java.lang.IllegalArgumentException (Showing top 20 results out of 297,711)

origin: stackoverflow.com

 if (string.contains("-")) {
  // Split it.
} else {
  throw new IllegalArgumentException("String " + string + " does not contain -");
}
origin: google/guava

private void assertCastFails(long value) {
 try {
  Chars.checkedCast(value);
  fail("Cast to char should have failed: " + value);
 } catch (IllegalArgumentException ex) {
  assertTrue(
    value + " not found in exception text: " + ex.getMessage(),
    ex.getMessage().contains(String.valueOf(value)));
 }
}
origin: google/guava

private static void assertCastFails(long value) {
 try {
  Shorts.checkedCast(value);
  fail("Cast to short should have failed: " + value);
 } catch (IllegalArgumentException ex) {
  assertTrue(
    value + " not found in exception text: " + ex.getMessage(),
    ex.getMessage().contains(String.valueOf(value)));
 }
}
origin: iluwatar/java-design-patterns

@Override
public void onPreCall() {
 if (n < 0) {
  throw new IllegalArgumentException("n is less than 0");
 }
}
origin: google/guava

private static void assertCastFails(long value) {
 try {
  SignedBytes.checkedCast(value);
  fail("Cast to byte should have failed: " + value);
 } catch (IllegalArgumentException ex) {
  assertTrue(
    value + " not found in exception text: " + ex.getMessage(),
    ex.getMessage().contains(String.valueOf(value)));
 }
}
origin: square/retrofit

 private static void checkPercentageValidity(int percentage, String message) {
  if (percentage < 0 || percentage > 100) {
   throw new IllegalArgumentException(message);
  }
 }
}
origin: google/guava

public void testToOptionalMultiple() {
 try {
  Stream.of(1, 2).collect(MoreCollectors.toOptional());
  fail("Expected IllegalArgumentException");
 } catch (IllegalArgumentException expected) {
  assertThat(expected.getMessage()).contains("1, 2");
 }
}
origin: square/okhttp

public static int checkDuration(String name, long duration, TimeUnit unit) {
 if (duration < 0) throw new IllegalArgumentException(name + " < 0");
 if (unit == null) throw new NullPointerException("unit == null");
 long millis = unit.toMillis(duration);
 if (millis > Integer.MAX_VALUE) throw new IllegalArgumentException(name + " too large.");
 if (millis == 0 && duration > 0) throw new IllegalArgumentException(name + " too small.");
 return (int) millis;
}
origin: google/guava

/** Can't create the map if more than one value maps to the same key. */
public void testUniqueIndexDuplicates() {
 try {
  Map<Integer, String> unused =
    Maps.uniqueIndex(ImmutableSet.of("one", "uno"), Functions.constant(1));
  fail();
 } catch (IllegalArgumentException expected) {
  assertThat(expected.getMessage()).contains("Multimaps.index");
 }
}
origin: square/retrofit

static void checkNotPrimitive(Type type) {
 if (type instanceof Class<?> && ((Class<?>) type).isPrimitive()) {
  throw new IllegalArgumentException();
 }
}
origin: google/guava

 public void testOnlyElementMany() {
  try {
   Stream.of(1, 2, 3, 4, 5, 6).collect(MoreCollectors.onlyElement());
   fail("Expected IllegalArgumentException");
  } catch (IllegalArgumentException expected) {
   assertThat(expected.getMessage()).contains("1, 2, 3, 4, 5, ...");
  }
 }
}
origin: square/retrofit

static Type getParameterUpperBound(int index, ParameterizedType type) {
 Type[] types = type.getActualTypeArguments();
 if (index < 0 || index >= types.length) {
  throw new IllegalArgumentException(
    "Index " + index + " not in range [0," + types.length + ") for " + type);
 }
 Type paramType = types[index];
 if (paramType instanceof WildcardType) {
  return ((WildcardType) paramType).getUpperBounds()[0];
 }
 return paramType;
}
origin: ReactiveX/RxJava

@SuppressWarnings("unchecked")
@Test
public void badCapacityHint() throws Exception {
  Observable<Integer> source = Observable.just(1);
  try {
    Observable.concatEager(Arrays.asList(source, source, source), 1, -99);
  } catch (IllegalArgumentException ex) {
    assertEquals("prefetch > 0 required but it was -99", ex.getMessage());
  }
}
origin: square/okhttp

@Override public void setFixedLengthStreamingMode(long contentLength) {
 if (super.connected) throw new IllegalStateException("Already connected");
 if (chunkLength > 0) throw new IllegalStateException("Already in chunked mode");
 if (contentLength < 0) throw new IllegalArgumentException("contentLength < 0");
 this.fixedContentLength = contentLength;
 super.fixedContentLength = (int) Math.min(contentLength, Integer.MAX_VALUE);
}
origin: google/guava

public void testOfWithDuplicateKey() {
 try {
  ImmutableBiMap.of("one", 1, "one", 1);
  fail();
 } catch (IllegalArgumentException expected) {
  assertThat(expected.getMessage()).contains("one");
 }
}
origin: square/retrofit

static RuntimeException methodError(Method method, @Nullable Throwable cause, String message,
  Object... args) {
 message = String.format(message, args);
 return new IllegalArgumentException(message
   + "\n    for method "
   + method.getDeclaringClass().getSimpleName()
   + "."
   + method.getName(), cause);
}
origin: ReactiveX/RxJava

@SuppressWarnings({ "unchecked", "rawtypes" })
@Test
public void mappingBadCapacityHint() throws Exception {
  Observable<Integer> source = Observable.just(1);
  try {
    Observable.just(source, source, source).concatMapEager((Function)Functions.identity(), 10, -99);
  } catch (IllegalArgumentException ex) {
    assertEquals("prefetch > 0 required but it was -99", ex.getMessage());
  }
}
origin: ReactiveX/RxJava

  @Override
  public boolean test(Integer t) throws Exception {
    throw new IllegalArgumentException();
  }
});
origin: ReactiveX/RxJava

@Test
public void takeNegative() {
  try {
    Observable.just(1).take(-99);
    fail("Should have thrown");
  } catch (IllegalArgumentException ex) {
    assertEquals("count >= 0 required but it was -99", ex.getMessage());
  }
}
origin: ReactiveX/RxJava

  @Override
  public Integer apply(Integer t1) {
    throw new IllegalArgumentException("some error");
  }
}).blockingSingle();
java.langIllegalArgumentException

Javadoc

Thrown to indicate that a method has been passed an illegal or inappropriate argument.

Most used methods

  • <init>
    Constructs a new exception with the specified cause and a detail message of (cause==null ? null : c
  • getMessage
  • printStackTrace
  • initCause
  • toString
  • getLocalizedMessage
  • getStackTrace
  • setStackTrace
  • getCause
  • addSuppressed
  • fillInStackTrace
  • getSuppressed
  • fillInStackTrace,
  • getSuppressed

Popular in Java

  • Creating JSON documents from java classes using gson
  • onCreateOptionsMenu (Activity)
  • getApplicationContext (Context)
  • scheduleAtFixedRate (ScheduledExecutorService)
  • MalformedURLException (java.net)
    This exception is thrown when a program attempts to create an URL from an incorrect specification.
  • Proxy (java.net)
    This class represents proxy server settings. A created instance of Proxy stores a type and an addres
  • Modifier (javassist)
    The Modifier class provides static methods and constants to decode class and member access modifiers
  • Cipher (javax.crypto)
    This class provides access to implementations of cryptographic ciphers for encryption and decryption
  • HttpServletRequest (javax.servlet.http)
    Extends the javax.servlet.ServletRequest interface to provide request information for HTTP servlets.
  • XPath (javax.xml.xpath)
    XPath provides access to the XPath evaluation environment and expressions. Evaluation of XPath Expr
  • Top 12 Jupyter Notebook extensions
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now