Skip to content

Commit 7217d3f

Browse files
committed
Exception for bad arguments changed to a derivative of NetLicensingException
1 parent 2a57bc5 commit 7217d3f

File tree

2 files changed

+50
-14
lines changed

2 files changed

+50
-14
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/* Licensed under the Apache License, Version 2.0 (the "License");
2+
* you may not use this file except in compliance with the License.
3+
* You may obtain a copy of the License at
4+
*
5+
* http://www.apache.org/licenses/LICENSE-2.0
6+
*
7+
* Unless required by applicable law or agreed to in writing, software
8+
* distributed under the License is distributed on an "AS IS" BASIS,
9+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
* See the License for the specific language governing permissions and
11+
* limitations under the License.
12+
*/
13+
package com.labs64.netlicensing.exception;
14+
15+
/**
16+
* Thrown when illegal arguments are passed to the NetLicensing client call.
17+
*/
18+
public class MalformedArgumentsException extends NetLicensingException {
19+
20+
private static final long serialVersionUID = -2548284543777416222L;
21+
22+
/**
23+
* Construct a <code>ConversionException</code> with the specified detail message.
24+
*
25+
* @param msg
26+
* the detail message
27+
*/
28+
public MalformedArgumentsException(final String msg) {
29+
super(msg);
30+
}
31+
32+
}

NetLicensingClient/src/main/java/com/labs64/netlicensing/util/CheckUtils.java

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,68 +12,72 @@
1212
*/
1313
package com.labs64.netlicensing.util;
1414

15+
import com.labs64.netlicensing.exception.MalformedArgumentsException;
16+
1517
/**
1618
* Common utilities for precondition checking.
1719
*/
1820
public class CheckUtils {
1921

2022
/**
2123
* Ensures that an object reference is not null.
22-
*
24+
*
2325
* @param object
2426
* object to check
2527
* @param msg
2628
* exception message
27-
* @throws IllegalArgumentException
29+
* @throws MalformedArgumentsException
2830
* if object is null
2931
*/
30-
public static void notNull(final Object object, final String msg) {
32+
private static void notNull(final Object object, final String msg) throws MalformedArgumentsException {
3133
if (object == null) {
32-
throw new IllegalArgumentException(msg);
34+
throw new MalformedArgumentsException(msg);
3335
}
3436
}
3537

3638
/**
3739
* Ensures that a string is not null or empty.
38-
*
40+
*
3941
* @param string
4042
* string to check
4143
* @param msg
4244
* exception message
43-
* @throws IllegalArgumentException
45+
* @throws MalformedArgumentsException
4446
* if string is null or empty
4547
*/
46-
public static void notEmpty(final String string, final String msg) {
48+
private static void notEmpty(final String string, final String msg) throws MalformedArgumentsException {
4749
if (string == null || string.length() == 0) {
48-
throw new IllegalArgumentException(msg);
50+
throw new MalformedArgumentsException(msg);
4951
}
5052
}
5153

5254
/**
5355
* Ensures that an object reference passed as a parameter to the calling method is not null.
54-
*
56+
*
5557
* @param parameter
5658
* param to check
5759
* @param parameterName
5860
* name of the parameter
59-
* @throws IllegalArgumentException
61+
* @throws MalformedArgumentsException
6062
* if parameter is null
6163
*/
62-
public static void paramNotNull(final Object parameter, final String parameterName) {
64+
public static void paramNotNull(final Object parameter, final String parameterName)
65+
throws MalformedArgumentsException {
6366
notNull(parameter, String.format("Parameter '%s' cannot be null", parameterName));
6467
}
6568

6669
/**
6770
* Ensures that a string passed as a parameter to the calling method is not null or empty.
68-
*
71+
*
6972
* @param parameter
7073
* param to check
7174
* @param parameterName
7275
* name of the parameter
73-
* @throws IllegalArgumentException
76+
* @throws MalformedArgumentsException
7477
* if parameter is null or empty
7578
*/
76-
public static void paramNotEmpty(final String parameter, final String parameterName) {
79+
public static void paramNotEmpty(final String parameter, final String parameterName)
80+
throws MalformedArgumentsException {
7781
notEmpty(parameter, String.format("Parameter '%s' cannot be null or empty string", parameterName));
7882
}
7983

0 commit comments

Comments
 (0)