|
27 | 27 | import java.io.InputStream; |
28 | 28 | import java.net.URL; |
29 | 29 | import java.security.ProtectionDomain; |
| 30 | +import java.util.ArrayList; |
30 | 31 | import java.util.Arrays; |
31 | 32 | import java.util.Collection; |
32 | 33 | import java.util.Collections; |
33 | 34 | import java.util.Enumeration; |
34 | 35 | import java.util.HashMap; |
35 | 36 | import java.util.HashSet; |
| 37 | +import java.util.List; |
36 | 38 | import java.util.Map; |
37 | 39 | import java.util.Properties; |
38 | 40 | import java.util.Set; |
39 | | -import java.util.StringTokenizer; |
40 | 41 | import java.util.concurrent.atomic.AtomicBoolean; |
41 | 42 | import java.util.jar.JarEntry; |
42 | 43 | import java.util.jar.JarFile; |
@@ -291,7 +292,7 @@ protected Set<String> createLoader(ModuleInfo m, ProxyClassLoader pcl, File jar) |
291 | 292 | } |
292 | 293 | } |
293 | 294 | if (exported instanceof String) { |
294 | | - for (String p : exported.toString().split(",")) { // NOI18N |
| 295 | + for (String p : splitExportPackages(exported.toString())) { |
295 | 296 | pkgs.add(extractBundleName(p)); |
296 | 297 | } |
297 | 298 | } |
@@ -800,4 +801,48 @@ private static Set<String> findRecursivePkgs(Module m, PackageExport packageExpo |
800 | 801 | public final byte[] patchBC(ClassLoader l, String className, ProtectionDomain pd, byte[] arr) { |
801 | 802 | return patchByteCode(l, className, pd, arr); |
802 | 803 | } |
| 804 | + |
| 805 | + static List<String> splitExportPackages(String exportPkg) { |
| 806 | + List<String> elements = new ArrayList<>(); |
| 807 | + StringBuilder buffer = new StringBuilder(); |
| 808 | + boolean inQuotedString = false; |
| 809 | + for (int i = 0; i < exportPkg.length(); i++) { |
| 810 | + char nextChar = exportPkg.charAt(i); |
| 811 | + switch(nextChar) { |
| 812 | + case '"' -> { |
| 813 | + inQuotedString = ! inQuotedString; |
| 814 | + buffer.append(nextChar); |
| 815 | + } |
| 816 | + case ',' -> { |
| 817 | + if (inQuotedString) { |
| 818 | + buffer.append(nextChar); |
| 819 | + } else { |
| 820 | + elements.add(buffer.toString()); |
| 821 | + buffer.setLength(0); |
| 822 | + } |
| 823 | + } |
| 824 | + case '\\' -> { |
| 825 | + buffer.append(nextChar); |
| 826 | + if (inQuotedString) { |
| 827 | + if((i + 1) == exportPkg.length()) { |
| 828 | + throw new IllegalStateException("Invalid escape sequence"); |
| 829 | + } |
| 830 | + nextChar = exportPkg.charAt(i + 1); |
| 831 | + i++; |
| 832 | + if (nextChar == '"' || nextChar == '\\') { |
| 833 | + buffer.append(nextChar); |
| 834 | + } else { |
| 835 | + throw new IllegalStateException("Invalid escape sequence"); |
| 836 | + } |
| 837 | + } |
| 838 | + } |
| 839 | + default -> buffer.append(nextChar); |
| 840 | + } |
| 841 | + } |
| 842 | + if(! buffer.isEmpty()){ |
| 843 | + elements.add(buffer.toString()); |
| 844 | + } |
| 845 | + return elements; |
| 846 | + } |
| 847 | + |
803 | 848 | } |
0 commit comments