< prev index next >

src/java.base/share/classes/jdk/internal/org/objectweb/asm/util/CheckMethodAdapter.java

Print this page
rev 51919 : 8215281: Use String.isEmpty() when applicable in java.base
Reviewed-by: dfuchs, alanb


1290         for (int i = start + 1; i < max; ++i) {
1291             if (!Character.isJavaIdentifierPart(name.charAt(i))) {
1292                 throw new IllegalArgumentException("Invalid " + msg
1293                         + " (must be a valid Java identifier): " + name);
1294             }
1295         }
1296     }
1297 
1298     /**
1299      * Checks that the given string is a valid Java identifier.
1300      *
1301      * @param version
1302      *            the class version.
1303      * @param name
1304      *            the string to be checked.
1305      * @param msg
1306      *            a message to be used in case of error.
1307      */
1308     static void checkMethodIdentifier(int version, final String name,
1309             final String msg) {
1310         if (name == null || name.length() == 0) {
1311             throw new IllegalArgumentException("Invalid " + msg
1312                     + " (must not be null or empty)");
1313         }
1314         if ((version & 0xFFFF) >= Opcodes.V1_5) {
1315             for (int i = 0; i < name.length(); ++i) {
1316                 if (".;[/<>".indexOf(name.charAt(i)) != -1) {
1317                     throw new IllegalArgumentException("Invalid " + msg
1318                             + " (must be a valid unqualified name): " + name);
1319                 }
1320             }
1321             return;
1322         }
1323         if (!Character.isJavaIdentifierStart(name.charAt(0))) {
1324             throw new IllegalArgumentException(
1325                     "Invalid "
1326                             + msg
1327                             + " (must be a '<init>', '<clinit>' or a valid Java identifier): "
1328                             + name);
1329         }
1330         for (int i = 1; i < name.length(); ++i) {
1331             if (!Character.isJavaIdentifierPart(name.charAt(i))) {
1332                 throw new IllegalArgumentException(
1333                         "Invalid "
1334                                 + msg
1335                                 + " (must be '<init>' or '<clinit>' or a valid Java identifier): "
1336                                 + name);
1337             }
1338         }
1339     }
1340 
1341     /**
1342      * Checks that the given string is a valid internal class name.
1343      *
1344      * @param name
1345      *            the string to be checked.
1346      * @param msg
1347      *            a message to be used in case of error.
1348      */
1349     static void checkInternalName(final String name, final String msg) {
1350         if (name == null || name.length() == 0) {
1351             throw new IllegalArgumentException("Invalid " + msg
1352                     + " (must not be null or empty)");
1353         }
1354         if (name.charAt(0) == '[') {
1355             checkDesc(name, false);
1356         } else {
1357             checkInternalName(name, 0, -1, msg);
1358         }
1359     }
1360 
1361     /**
1362      * Checks that the given substring is a valid internal class name.
1363      *
1364      * @param name
1365      *            the string to be checked.
1366      * @param start
1367      *            index of the first character of the identifier (inclusive).
1368      * @param end
1369      *            index of the last character of the identifier (exclusive). -1
1370      *            is equivalent to <tt>name.length()</tt> if name is not




1290         for (int i = start + 1; i < max; ++i) {
1291             if (!Character.isJavaIdentifierPart(name.charAt(i))) {
1292                 throw new IllegalArgumentException("Invalid " + msg
1293                         + " (must be a valid Java identifier): " + name);
1294             }
1295         }
1296     }
1297 
1298     /**
1299      * Checks that the given string is a valid Java identifier.
1300      *
1301      * @param version
1302      *            the class version.
1303      * @param name
1304      *            the string to be checked.
1305      * @param msg
1306      *            a message to be used in case of error.
1307      */
1308     static void checkMethodIdentifier(int version, final String name,
1309             final String msg) {
1310         if (name == null || name.isEmpty()) {
1311             throw new IllegalArgumentException("Invalid " + msg
1312                     + " (must not be null or empty)");
1313         }
1314         if ((version & 0xFFFF) >= Opcodes.V1_5) {
1315             for (int i = 0; i < name.length(); ++i) {
1316                 if (".;[/<>".indexOf(name.charAt(i)) != -1) {
1317                     throw new IllegalArgumentException("Invalid " + msg
1318                             + " (must be a valid unqualified name): " + name);
1319                 }
1320             }
1321             return;
1322         }
1323         if (!Character.isJavaIdentifierStart(name.charAt(0))) {
1324             throw new IllegalArgumentException(
1325                     "Invalid "
1326                             + msg
1327                             + " (must be a '<init>', '<clinit>' or a valid Java identifier): "
1328                             + name);
1329         }
1330         for (int i = 1; i < name.length(); ++i) {
1331             if (!Character.isJavaIdentifierPart(name.charAt(i))) {
1332                 throw new IllegalArgumentException(
1333                         "Invalid "
1334                                 + msg
1335                                 + " (must be '<init>' or '<clinit>' or a valid Java identifier): "
1336                                 + name);
1337             }
1338         }
1339     }
1340 
1341     /**
1342      * Checks that the given string is a valid internal class name.
1343      *
1344      * @param name
1345      *            the string to be checked.
1346      * @param msg
1347      *            a message to be used in case of error.
1348      */
1349     static void checkInternalName(final String name, final String msg) {
1350         if (name == null || name.isEmpty()) {
1351             throw new IllegalArgumentException("Invalid " + msg
1352                     + " (must not be null or empty)");
1353         }
1354         if (name.charAt(0) == '[') {
1355             checkDesc(name, false);
1356         } else {
1357             checkInternalName(name, 0, -1, msg);
1358         }
1359     }
1360 
1361     /**
1362      * Checks that the given substring is a valid internal class name.
1363      *
1364      * @param name
1365      *            the string to be checked.
1366      * @param start
1367      *            index of the first character of the identifier (inclusive).
1368      * @param end
1369      *            index of the last character of the identifier (exclusive). -1
1370      *            is equivalent to <tt>name.length()</tt> if name is not


< prev index next >