< prev index next >

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

Print this page
rev 52979 : 8215281: Use String.isEmpty() when applicable in java.base
Reviewed-by: TBD


1297             return;
1298         }
1299         for (int i = startPos; i < max; i = name.offsetByCodePoints(i, 1)) {
1300             if (i == startPos
1301                     ? !Character.isJavaIdentifierStart(name.codePointAt(i))
1302                     : !Character.isJavaIdentifierPart(name.codePointAt(i))) {
1303                 throw new IllegalArgumentException(
1304                         INVALID + message + " (must be a valid Java identifier): " + name);
1305             }
1306         }
1307     }
1308 
1309     /**
1310       * Checks that the given string is a valid Java identifier.
1311       *
1312       * @param version the class version.
1313       * @param name the string to be checked.
1314       * @param message the message to use in case of error.
1315       */
1316     static void checkMethodIdentifier(final int version, final String name, final String message) {
1317         if (name == null || name.length() == 0) {
1318             throw new IllegalArgumentException(INVALID + message + MUST_NOT_BE_NULL_OR_EMPTY);
1319         }
1320         if ((version & 0xFFFF) >= Opcodes.V1_5) {
1321             for (int i = 0; i < name.length(); i = name.offsetByCodePoints(i, 1)) {
1322                 if (".;[/<>".indexOf(name.codePointAt(i)) != -1) {
1323                     throw new IllegalArgumentException(
1324                             INVALID + message + " (must be a valid unqualified name): " + name);
1325                 }
1326             }
1327             return;
1328         }
1329         for (int i = 0; i < name.length(); i = name.offsetByCodePoints(i, 1)) {
1330             if (i == 0
1331                     ? !Character.isJavaIdentifierStart(name.codePointAt(i))
1332                     : !Character.isJavaIdentifierPart(name.codePointAt(i))) {
1333                 throw new IllegalArgumentException(
1334                         INVALID
1335                                 + message
1336                                 + " (must be a '<init>', '<clinit>' or a valid Java identifier): "
1337                                 + name);
1338             }
1339         }
1340     }
1341 
1342     /**
1343       * Checks that the given string is a valid internal class name or array type descriptor.
1344       *
1345       * @param version the class version.
1346       * @param name the string to be checked.
1347       * @param message the message to use in case of error.
1348       */
1349     static void checkInternalName(final int version, final String name, final String message) {
1350         if (name == null || name.length() == 0) {
1351             throw new IllegalArgumentException(INVALID + message + MUST_NOT_BE_NULL_OR_EMPTY);
1352         }
1353         if (name.charAt(0) == '[') {
1354             checkDescriptor(version, name, false);
1355         } else {
1356             checkInternalClassName(version, name, message);
1357         }
1358     }
1359 
1360     /**
1361       * Checks that the given string is a valid internal class name.
1362       *
1363       * @param version the class version.
1364       * @param name the string to be checked.
1365       * @param message the message to use in case of error.
1366       */
1367     private static void checkInternalClassName(
1368             final int version, final String name, final String message) {
1369         try {
1370             int startIndex = 0;


1440                     throw new IllegalArgumentException(INVALID_DESCRIPTOR + descriptor);
1441                 }
1442                 try {
1443                     checkInternalClassName(version, descriptor.substring(startPos + 1, endPos), null);
1444                 } catch (IllegalArgumentException e) {
1445                     throw new IllegalArgumentException(INVALID_DESCRIPTOR + descriptor, e);
1446                 }
1447                 return endPos + 1;
1448             default:
1449                 throw new IllegalArgumentException(INVALID_DESCRIPTOR + descriptor);
1450         }
1451     }
1452 
1453     /**
1454       * Checks that the given string is a valid method descriptor.
1455       *
1456       * @param version the class version.
1457       * @param descriptor the string to be checked.
1458       */
1459     static void checkMethodDescriptor(final int version, final String descriptor) {
1460         if (descriptor == null || descriptor.length() == 0) {
1461             throw new IllegalArgumentException("Invalid method descriptor (must not be null or empty)");
1462         }
1463         if (descriptor.charAt(0) != '(' || descriptor.length() < 3) {
1464             throw new IllegalArgumentException(INVALID_DESCRIPTOR + descriptor);
1465         }
1466         int pos = 1;
1467         if (descriptor.charAt(pos) != ')') {
1468             do {
1469                 if (descriptor.charAt(pos) == 'V') {
1470                     throw new IllegalArgumentException(INVALID_DESCRIPTOR + descriptor);
1471                 }
1472                 pos = checkDescriptor(version, descriptor, pos, false);
1473             } while (pos < descriptor.length() && descriptor.charAt(pos) != ')');
1474         }
1475         pos = checkDescriptor(version, descriptor, pos + 1, true);
1476         if (pos != descriptor.length()) {
1477             throw new IllegalArgumentException(INVALID_DESCRIPTOR + descriptor);
1478         }
1479     }
1480 


1297             return;
1298         }
1299         for (int i = startPos; i < max; i = name.offsetByCodePoints(i, 1)) {
1300             if (i == startPos
1301                     ? !Character.isJavaIdentifierStart(name.codePointAt(i))
1302                     : !Character.isJavaIdentifierPart(name.codePointAt(i))) {
1303                 throw new IllegalArgumentException(
1304                         INVALID + message + " (must be a valid Java identifier): " + name);
1305             }
1306         }
1307     }
1308 
1309     /**
1310       * Checks that the given string is a valid Java identifier.
1311       *
1312       * @param version the class version.
1313       * @param name the string to be checked.
1314       * @param message the message to use in case of error.
1315       */
1316     static void checkMethodIdentifier(final int version, final String name, final String message) {
1317         if (name == null || name.isEmpty()) {
1318             throw new IllegalArgumentException(INVALID + message + MUST_NOT_BE_NULL_OR_EMPTY);
1319         }
1320         if ((version & 0xFFFF) >= Opcodes.V1_5) {
1321             for (int i = 0; i < name.length(); i = name.offsetByCodePoints(i, 1)) {
1322                 if (".;[/<>".indexOf(name.codePointAt(i)) != -1) {
1323                     throw new IllegalArgumentException(
1324                             INVALID + message + " (must be a valid unqualified name): " + name);
1325                 }
1326             }
1327             return;
1328         }
1329         for (int i = 0; i < name.length(); i = name.offsetByCodePoints(i, 1)) {
1330             if (i == 0
1331                     ? !Character.isJavaIdentifierStart(name.codePointAt(i))
1332                     : !Character.isJavaIdentifierPart(name.codePointAt(i))) {
1333                 throw new IllegalArgumentException(
1334                         INVALID
1335                                 + message
1336                                 + " (must be a '<init>', '<clinit>' or a valid Java identifier): "
1337                                 + name);
1338             }
1339         }
1340     }
1341 
1342     /**
1343       * Checks that the given string is a valid internal class name or array type descriptor.
1344       *
1345       * @param version the class version.
1346       * @param name the string to be checked.
1347       * @param message the message to use in case of error.
1348       */
1349     static void checkInternalName(final int version, final String name, final String message) {
1350         if (name == null || name.isEmpty()) {
1351             throw new IllegalArgumentException(INVALID + message + MUST_NOT_BE_NULL_OR_EMPTY);
1352         }
1353         if (name.charAt(0) == '[') {
1354             checkDescriptor(version, name, false);
1355         } else {
1356             checkInternalClassName(version, name, message);
1357         }
1358     }
1359 
1360     /**
1361       * Checks that the given string is a valid internal class name.
1362       *
1363       * @param version the class version.
1364       * @param name the string to be checked.
1365       * @param message the message to use in case of error.
1366       */
1367     private static void checkInternalClassName(
1368             final int version, final String name, final String message) {
1369         try {
1370             int startIndex = 0;


1440                     throw new IllegalArgumentException(INVALID_DESCRIPTOR + descriptor);
1441                 }
1442                 try {
1443                     checkInternalClassName(version, descriptor.substring(startPos + 1, endPos), null);
1444                 } catch (IllegalArgumentException e) {
1445                     throw new IllegalArgumentException(INVALID_DESCRIPTOR + descriptor, e);
1446                 }
1447                 return endPos + 1;
1448             default:
1449                 throw new IllegalArgumentException(INVALID_DESCRIPTOR + descriptor);
1450         }
1451     }
1452 
1453     /**
1454       * Checks that the given string is a valid method descriptor.
1455       *
1456       * @param version the class version.
1457       * @param descriptor the string to be checked.
1458       */
1459     static void checkMethodDescriptor(final int version, final String descriptor) {
1460         if (descriptor == null || descriptor.isEmpty()) {
1461             throw new IllegalArgumentException("Invalid method descriptor (must not be null or empty)");
1462         }
1463         if (descriptor.charAt(0) != '(' || descriptor.length() < 3) {
1464             throw new IllegalArgumentException(INVALID_DESCRIPTOR + descriptor);
1465         }
1466         int pos = 1;
1467         if (descriptor.charAt(pos) != ')') {
1468             do {
1469                 if (descriptor.charAt(pos) == 'V') {
1470                     throw new IllegalArgumentException(INVALID_DESCRIPTOR + descriptor);
1471                 }
1472                 pos = checkDescriptor(version, descriptor, pos, false);
1473             } while (pos < descriptor.length() && descriptor.charAt(pos) != ')');
1474         }
1475         pos = checkDescriptor(version, descriptor, pos + 1, true);
1476         if (pos != descriptor.length()) {
1477             throw new IllegalArgumentException(INVALID_DESCRIPTOR + descriptor);
1478         }
1479     }
1480 
< prev index next >