checkArgument(count > 0, "must be positive: %s", count);
Note that the sense of the expression is inverted; with Preconditions you declare what
you expect to be true, just as you do with an assert or a
JUnit assertTrue call.
the exception message to use if the check fails; will be converted to a
string using String#valueOf(Object) if not null (a null will not be converted).
a template for the exception message should the check fail. The
message is formed using String#format(String, Object...). if not null (a null will
not be converted).
the exception message to use if the check fails; will be converted to a
string using String#valueOf(Object) if not null (a null will not be converted).
a template for the exception message should the check fail. The
message is formed using String#format(String, Object...). if not null (a null will
not be converted).
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-09-04 UTC."],[[["\u003cp\u003e\u003ccode\u003ePreconditions\u003c/code\u003e class offers static methods to validate method arguments and object states, simplifying checks and making code more compact.\u003c/p\u003e\n"],["\u003cp\u003eIt replaces verbose \u003ccode\u003eif\u003c/code\u003e statements that throw exceptions with concise \u003ccode\u003echeckArgument\u003c/code\u003e or \u003ccode\u003echeckState\u003c/code\u003e method calls, which verify conditions.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003echeckNotNull\u003c/code\u003e method ensures that a provided object reference is not null, throwing an exception if it is, and providing an optional error message.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003echeckArgument\u003c/code\u003e verifies that an expression involving one or more method parameters is true, and it includes error message and formatting capabilities.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003echeckState\u003c/code\u003e confirms the truth of an expression regarding the state of the calling instance, also with error message customization.\u003c/p\u003e\n"]]],[],null,["# Class Preconditions (2.0.0)\n\n public final class Preconditions\n\nSimple static methods to be called at the start of your own methods to verify correct arguments\nand state. This allows constructs such as \n\n\n if (count \u003c= 0)=\"\" {=\"\" throw=\"\" new=\"\" illegalargumentexception(\"must=\"\" be=\"\" positive:=\"\" \"=\"\" +=\"\" count);=\"\" }=\"\"\u003e\n\nto be replaced with the more compact \n\n checkArgument(count \u003e 0, \"must be positive: %s\", count);\n\nNote that the sense of the expression is inverted; with `Preconditions` you declare what\nyou expect to be *true* , just as you do with an [`assert`](http://java.sun.com/j2se/1.5.0/docs/guide/language/assert.html) or a\nJUnit `assertTrue` call.\n\n**Note:** This class is a copy of a very old version of Guava's Preconditions. Please use\nthe current Guava version instead.\nSee Also: \"\u003chttps://google.github.io/guava/releases/21.0/api/docs/com/google/common/base/Preconditions.html\u003e\" \n\nInheritance\n-----------\n\n[java.lang.Object](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html) \\\u003e Preconditions \n\nInherited Members\n-----------------\n\n[Object.clone()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#clone--) \n[Object.equals(Object)](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#equals-java.lang.Object-) \n[Object.finalize()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#finalize--) \n[Object.getClass()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#getClass--) \n[Object.hashCode()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#hashCode--) \n[Object.notify()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#notify--) \n[Object.notifyAll()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#notifyAll--) \n[Object.toString()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#toString--) \n[Object.wait()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#wait--) \n[Object.wait(long)](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#wait-long-) \n[Object.wait(long,int)](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#wait-long-int-)\n\nStatic Methods\n--------------\n\n### \\\u003cT\\\u003echeckNotNull(T reference, @Nullable Object errorMessage)\n\n public static T \u003cT\u003echeckNotNull(T reference, @Nullable Object errorMessage)\n\nEnsures that an object reference passed as a parameter to the calling method is not null.\n\n### checkArgument(boolean expression, @Nullable Object errorMessage)\n\n public static void checkArgument(boolean expression, @Nullable Object errorMessage)\n\nEnsures the truth of an expression involving one or more parameters to the calling method.\n\n### checkArgument(boolean expression, @Nullable String errorMessageTemplate, @Nullable Object\\[\\] errorMessageArgs)\n\n public static void checkArgument(boolean expression, @Nullable String errorMessageTemplate, @Nullable Object[] errorMessageArgs)\n\nEnsures the truth of an expression involving one or more parameters to the calling method.\n\n### checkState(boolean expression, @Nullable String errorMessage)\n\n public static void checkState(boolean expression, @Nullable String errorMessage)\n\nEnsures the truth of an expression involving the state of the calling instance.\n\n### checkState(boolean expression, @Nullable String errorMessageTemplate, @Nullable Object\\[\\] errorMessageArgs)\n\n public static void checkState(boolean expression, @Nullable String errorMessageTemplate, @Nullable Object[] errorMessageArgs)\n\nEnsures the truth of an expression involving the state of the calling instance."]]