@@ -71,16 +71,17 @@ typedef struct URLElements {
71
71
} URLElements ;
72
72
73
73
74
- static J9ClassPathEntry * getCachedURL (JNIEnv * env , jint helperID , const char * pathChars , jsize pathLen , UDATA cpeType , U_16 cpeStatus );
74
+ static J9ClassPathEntry * getCachedURL (JNIEnv * env , jint helperID , const char * pathChars , jsize pathLen , UDATA cpeType , U_16 cpeStatus , const char * correctedPath );
75
75
static const char * copyString (J9PortLibrary * portlib , const char * toCopy , UDATA length , J9SharedStringFarm * * farmRoot , const J9UTF8 * * makeUTF8 );
76
76
UDATA urlHashFn (void * item , void * userData );
77
- static jint createURLEntry (JNIEnv * env , jint helperID , J9ClassPathEntry * * cpEntry_ , char * correctedPathCopy , UDATA cpeType , U_16 cpeStatus );
77
+ static jint createURLEntry (JNIEnv * env , jint helperID , J9ClassPathEntry * * cpEntry_ , const char * correctedPathCopy , UDATA cpeType , U_16 cpeStatus );
78
78
UDATA utfHashEqualFn (void * left , void * right , void * userData );
79
79
static jint createROMClassCookie (JNIEnv * env , J9JavaVM * vm , J9ROMClass * romClass , jbyteArray romClassCookieBuffer );
80
80
static jint createToken (JNIEnv * env , jint helperID , J9ClassPathEntry * * cpEntry_ , const char * tokenChars , jsize tokenSize );
81
81
static UDATA correctURLPath (JNIEnv * env , const char * pathChars , jsize pathLen , char * * correctedPathPtr , J9SharedStringFarm * * jclStringFarm );
82
82
static const char * getCachedString (JNIEnv * env , const char * input , jsize length , J9SharedStringFarm * * farmRoot , const J9UTF8 * * getUTF8 );
83
- static UDATA getCpeTypeForProtocol (char * protocol , jsize protocolLen , const char * pathChars , jsize pathLen );
83
+ static UDATA getCpeTypeForProtocol (JNIEnv * env , const char * protocol , jsize protocolLen , const char * urlPathChars , jsize urlPathLen , char * * correctedPathPtr );
84
+ static BOOLEAN isPathTypeJimage (const char * pathChars , jsize pathLen );
84
85
static void getURLMethodIDs (JNIEnv * env );
85
86
static J9Pool * getClasspathCache (JNIEnv * env );
86
87
static J9Pool * getURLCache (JNIEnv * env );
@@ -122,14 +123,14 @@ correctURLPath(JNIEnv* env, const char* pathChars, jsize pathLen, char** correct
122
123
returnVal = 1 ;
123
124
startOffset = 0 ;
124
125
125
- #ifdef WIN32
126
+ #if defined( WIN32 )
126
127
for (;pathChars [startOffset ]== '/' ; startOffset ++ );
127
128
128
129
/* If Windows UNC (no path colon) do not remove leading spaces */
129
130
if (pathChars [startOffset + 1 ] != ':' ) {
130
131
startOffset = 0 ;
131
132
}
132
- #endif
133
+ #endif /* defined(WIN32) */
133
134
134
135
if (pathLen >= STACK_STRINGBUF_SIZE ) {
135
136
if (!(bufPtr = (char * )j9mem_allocate_memory ((pathLen + 1 ) * sizeof (char ), J9MEM_CATEGORY_VM_JCL ))) {
@@ -147,11 +148,11 @@ correctURLPath(JNIEnv* env, const char* pathChars, jsize pathLen, char** correct
147
148
if (i == (pathLen - 1 )) {
148
149
current = '\0' ; /* remove trailing slash */
149
150
}
150
- #ifdef WIN32
151
+ #if defined( WIN32 )
151
152
else {
152
153
current = '\\' ; /* convert / to \\ */
153
154
}
154
- #endif
155
+ #endif /* defined(WIN32) */
155
156
}
156
157
157
158
/* Assumes escape sequence is %nn, where nn is hex value */
@@ -229,7 +230,6 @@ createROMClassCookie(JNIEnv* env, J9JavaVM* vm, J9ROMClass* romClass, jbyteArray
229
230
static jint
230
231
createCPEntries (JNIEnv * env , jint helperID , jint urlCount , J9ClassPathEntry * * * cpEntries_ , URLElements * urlArrayElements )
231
232
{
232
- J9JavaVM * vm = ((J9VMThread * )env )-> javaVM ;
233
233
J9ClassPathEntry * cpEntries = NULL ;
234
234
struct J9ClasspathByID * newCacheItem = NULL ;
235
235
J9ClassPathEntry * * cpePtrArray = NULL ;
@@ -251,23 +251,23 @@ createCPEntries(JNIEnv* env, jint helperID, jint urlCount, J9ClassPathEntry*** c
251
251
memset (cpePtrArray , 0 , cpEntrySize );
252
252
cpEntries = (J9ClassPathEntry * )((char * )cpePtrArray + (urlCount * (sizeof (J9ClassPathEntry * ))));
253
253
254
- for (i = 0 ; i < urlCount ; i ++ ) {
255
- UDATA cpeType = 0 ;
256
- char * correctPath = NULL ;
257
-
258
- cpeType = getCpeTypeForProtocol ((char * )urlArrayElements [i ].protocolChars , urlArrayElements [i ].protocolLen , urlArrayElements [i ].pathChars , urlArrayElements [i ].pathLen );
254
+ for (i = 0 ; i < urlCount ; i ++ ) {
255
+ char * correctedPath = NULL ;
256
+ UDATA cpeType = getCpeTypeForProtocol (
257
+ env ,
258
+ urlArrayElements [i ].protocolChars ,
259
+ urlArrayElements [i ].protocolLen ,
260
+ urlArrayElements [i ].pathChars ,
261
+ urlArrayElements [i ].pathLen ,
262
+ & correctedPath );
259
263
if (CPE_TYPE_UNKNOWN == cpeType ) {
260
264
Trc_JCL_com_ibm_oti_shared_createCPEntries_ExitFalse4 (env );
261
265
goto _error ;
262
266
}
263
- if (!correctURLPath (env , urlArrayElements [i ].pathChars , urlArrayElements [i ].pathLen , & correctPath , & (vm -> sharedClassConfig -> jclStringFarm ))) {
264
- Trc_JCL_com_ibm_oti_shared_createCPEntries_ExitFalse5 (env );
265
- goto _error ;
266
- }
267
267
268
- cpEntries [i ].path = (U_8 * ) correctPath ;
268
+ cpEntries [i ].path = (U_8 * ) correctedPath ;
269
269
cpEntries [i ].extraInfo = NULL ;
270
- cpEntries [i ].pathLength = (U_32 )strlen (correctPath );
270
+ cpEntries [i ].pathLength = (U_32 )strlen (correctedPath );
271
271
cpEntries [i ].flags = 0 ;
272
272
cpEntries [i ].type = (U_16 )cpeType ;
273
273
cpePtrArray [i ] = & cpEntries [i ];
@@ -455,11 +455,10 @@ getURLMethodIDs(JNIEnv* env)
455
455
return ;
456
456
}
457
457
458
-
459
- /* Note:CorrectedPathCopy must be a copied string which will not disappear and partition must be also not disappear */
458
+ /* Note: correctedPathCopy must not disappear. */
460
459
/* THREADING: Must be protected by jclCacheMutex */
461
460
static jint
462
- createURLEntry (JNIEnv * env , jint helperID , J9ClassPathEntry * * cpEntry_ , char * correctedPathCopy , UDATA cpeType , U_16 cpeStatus )
461
+ createURLEntry (JNIEnv * env , jint helperID , J9ClassPathEntry * * cpEntry_ , const char * correctedPathCopy , UDATA cpeType , U_16 cpeStatus )
463
462
{
464
463
J9JavaVM * vm = ((J9VMThread * )env )-> javaVM ;
465
464
J9ClassPathEntry * newEntry ;
@@ -546,40 +545,67 @@ getPathProtocolFromURL(JNIEnv* env, jobject url, jmethodID URLgetPathID, jmethod
546
545
return rc ;
547
546
}
548
547
548
+ static BOOLEAN
549
+ isPathTypeJimage (const char * pathChars , jsize pathLen )
550
+ {
551
+ char JimageEndsWith [] = DIR_SEPARATOR_STR "lib" DIR_SEPARATOR_STR "modules" ;
552
+ IDATA len = LITERAL_STRLEN (JimageEndsWith );
553
+
554
+ if (pathLen > len ) {
555
+ const char * endsWith = pathChars + (pathLen - len );
556
+ if (0 == strncmp (endsWith , JimageEndsWith , len )) {
557
+ return TRUE;
558
+ }
559
+ }
560
+ return FALSE;
561
+ }
549
562
550
563
/* THREADING: Can be called multi-threaded */
551
564
static UDATA
552
- getCpeTypeForProtocol (char * protocol , jsize protocolLen , const char * pathChars , jsize pathLen )
565
+ getCpeTypeForProtocol (JNIEnv * env , const char * protocol , jsize protocolLen , const char * urlPathChars , jsize urlPathLen , char * * correctedPathPtr )
553
566
{
567
+ J9JavaVM * vm = ((J9VMThread * )env )-> javaVM ;
568
+ const char * pathChars = NULL ;
569
+ jsize pathLen = 0 ;
570
+
554
571
Trc_JCL_com_ibm_oti_shared_getCpeTypeForProtocol_Entry ();
555
572
556
- if (!protocol ) {
557
- Trc_JCL_com_ibm_oti_shared_getCpeTypeForProtocol_Exit0 ();
558
- return 0 ;
573
+ if (NULL == protocol ) {
574
+ Trc_JCL_com_ibm_oti_shared_getCpeTypeForProtocol_ExitFail1 ();
575
+ return CPE_TYPE_UNKNOWN ;
576
+ }
577
+ if (!correctURLPath (env , urlPathChars , urlPathLen , correctedPathPtr , & (vm -> sharedClassConfig -> jclStringFarm ))) {
578
+ Trc_JCL_com_ibm_oti_shared_getCpeTypeForProtocol_ExitFail2 ();
579
+ return CPE_TYPE_UNKNOWN ;
559
580
}
560
- if (strncmp (protocol , "jar" , 4 )== 0 ) {
581
+ if (0 == strncmp (protocol , "jar" , 4 )) {
561
582
Trc_JCL_com_ibm_oti_shared_getCpeTypeForProtocol_ExitJAR ();
562
583
return CPE_TYPE_JAR ;
563
584
}
564
- if (strncmp (protocol , "file" , 5 )== 0 ) {
565
- char * endsWith = (char * )(pathChars + (pathLen - 4 ));
566
- if ((strncmp (endsWith , ".jar" , 4 )== 0 ) || (strncmp (endsWith , ".zip" , 4 )== 0 ) || strstr (pathChars ,"!/" ) || strstr (pathChars ,"!\\" )) {
585
+ pathChars = * correctedPathPtr ;
586
+ pathLen = (jsize )strlen (pathChars );
587
+ if (0 == strncmp (protocol , "file" , 5 )) {
588
+ if ((NULL != strstr (pathChars , "!/" )) || (NULL != strstr (pathChars , "!\\" ))) {
589
+ /* file is a fat jar */
567
590
Trc_JCL_com_ibm_oti_shared_getCpeTypeForProtocol_ExitJAR ();
568
591
return CPE_TYPE_JAR ;
592
+ } else if (isPathTypeJimage (pathChars , pathLen )) {
593
+ Trc_JCL_com_ibm_oti_shared_getCpeTypeForProtocol_ExitJIMAGE ();
594
+ return CPE_TYPE_JIMAGE ;
569
595
} else {
570
- char JimageEndsWith [] = DIR_SEPARATOR_STR "lib" DIR_SEPARATOR_STR "modules" ;
571
- IDATA len = LITERAL_STRLEN (JimageEndsWith );
572
-
573
- if (pathLen >= len ) {
574
- endsWith = (char * )(pathChars + (pathLen - len ));
575
- if (strncmp (endsWith , JimageEndsWith , len ) == 0 ) {
576
- Trc_JCL_com_ibm_oti_shared_getCpeTypeForProtocol_ExitJIMAGE ();
577
- return CPE_TYPE_JIMAGE ;
578
- }
596
+ PORT_ACCESS_FROM_JAVAVM (vm );
597
+ I_32 result = j9file_attr (pathChars );
598
+ if (EsIsFile == result ) {
599
+ Trc_JCL_com_ibm_oti_shared_getCpeTypeForProtocol_ExitJAR ();
600
+ return CPE_TYPE_JAR ;
601
+ } else if (EsIsDir == result ) {
602
+ Trc_JCL_com_ibm_oti_shared_getCpeTypeForProtocol_ExitDIR ();
603
+ return CPE_TYPE_DIRECTORY ;
604
+ } else {
605
+ Trc_JCL_com_ibm_oti_shared_getCpeTypeForProtocol_ExitFail3 (result );
606
+ return CPE_TYPE_UNKNOWN ;
579
607
}
580
608
}
581
- Trc_JCL_com_ibm_oti_shared_getCpeTypeForProtocol_ExitDIR ();
582
- return CPE_TYPE_DIRECTORY ;
583
609
}
584
610
Trc_JCL_com_ibm_oti_shared_getCpeTypeForProtocol_UnknownProtocol (protocolLen , protocol , pathLen , pathChars );
585
611
Trc_JCL_com_ibm_oti_shared_getCpeTypeForProtocol_ExitUnknown ();
@@ -588,8 +614,8 @@ getCpeTypeForProtocol(char* protocol, jsize protocolLen, const char* pathChars,
588
614
589
615
590
616
/* THREADING: Must be protected by jclCacheMutex */
591
- static J9ClassPathEntry *
592
- getCachedURL (JNIEnv * env , jint helperID , const char * pathChars , jsize pathLen , UDATA cpeType , U_16 cpeStatus )
617
+ static J9ClassPathEntry *
618
+ getCachedURL (JNIEnv * env , jint helperID , const char * pathChars , jsize pathLen , UDATA cpeType , U_16 cpeStatus , const char * correctedPath )
593
619
{
594
620
J9JavaVM * vm = ((J9VMThread * )env )-> javaVM ;
595
621
struct URLhtEntry * anElement = NULL ;
@@ -617,7 +643,6 @@ getCachedURL(JNIEnv* env, jint helperID, const char* pathChars, jsize pathLen, U
617
643
} else {
618
644
URLhtEntry newEntry ;
619
645
const char * origPathCopy ;
620
- char * correctedPathCopy ;
621
646
622
647
/* We must make a copy of the path
623
648
This is kept in the URLhtEntry and must be valid for the lifetime of the JVM */
@@ -626,9 +651,7 @@ getCachedURL(JNIEnv* env, jint helperID, const char* pathChars, jsize pathLen, U
626
651
goto _error ;
627
652
}
628
653
629
- /* Function returns a corrected copy of pathChars into correctedPathCopy. */
630
- correctURLPath (env , pathChars , pathLen , & correctedPathCopy , & (config -> jclStringFarm ));
631
- if (!createURLEntry (env , helperID , & urlEntry , correctedPathCopy , cpeType , cpeStatus )) {
654
+ if (!createURLEntry (env , helperID , & urlEntry , correctedPath , cpeType , cpeStatus )) {
632
655
goto _error ;
633
656
}
634
657
@@ -1230,6 +1253,7 @@ Java_com_ibm_oti_shared_SharedClassURLHelperImpl_findSharedClassImpl3(JNIEnv* en
1230
1253
U_16 cpeStatus = minimizeUpdateChecks ? CPE_STATUS_IGNORE_ZIP_LOAD_STATE : 0 ;
1231
1254
J9ClassLoader * classloader ;
1232
1255
URLElements urlElements = {0 };
1256
+ char * correctedPath = NULL ;
1233
1257
1234
1258
Trc_JCL_com_ibm_oti_shared_SharedClassURLHelperImpl_findSharedClassImpl_Entry (env , helperID );
1235
1259
@@ -1261,13 +1285,21 @@ Java_com_ibm_oti_shared_SharedClassURLHelperImpl_findSharedClassImpl3(JNIEnv* en
1261
1285
if (!getStringPair (env , & nameChars , & nameLen , & partitionChars , & partitionLen , classNameObj , partitionObj )) {
1262
1286
goto _errorPostClassNamePartition ;
1263
1287
}
1264
- if (!(cpeType = getCpeTypeForProtocol ((char * )urlElements .protocolChars , urlElements .protocolLen , urlElements .pathChars , urlElements .pathLen ))) {
1288
+ cpeType = getCpeTypeForProtocol (
1289
+ env ,
1290
+ urlElements .protocolChars ,
1291
+ urlElements .protocolLen ,
1292
+ urlElements .pathChars ,
1293
+ urlElements .pathLen ,
1294
+ & correctedPath );
1295
+ if (CPE_TYPE_UNKNOWN == cpeType ) {
1265
1296
goto _errorPostClassNamePartition ;
1266
1297
}
1267
1298
1268
1299
omrthread_monitor_enter (jclCacheMutex );
1269
1300
1270
- if (!(urlEntry = getCachedURL (env , helperID , urlElements .pathChars , urlElements .pathLen , cpeType , cpeStatus ))) {
1301
+ urlEntry = getCachedURL (env , helperID , urlElements .pathChars , urlElements .pathLen , cpeType , cpeStatus , correctedPath );
1302
+ if (NULL == urlEntry ) {
1271
1303
omrthread_monitor_exit (jclCacheMutex );
1272
1304
goto _errorPostClassNamePartition ;
1273
1305
}
@@ -1341,6 +1373,7 @@ Java_com_ibm_oti_shared_SharedClassURLHelperImpl_storeSharedClassImpl3(JNIEnv* e
1341
1373
SCAbstractAPI * sharedapi = (SCAbstractAPI * )(config -> sharedAPIObject );
1342
1374
U_16 cpeStatus = minimizeUpdateChecks ? CPE_STATUS_IGNORE_ZIP_LOAD_STATE : 0 ;
1343
1375
URLElements urlElements = {0 };
1376
+ char * correctedPath = NULL ;
1344
1377
1345
1378
Trc_JCL_com_ibm_oti_shared_SharedClassURLHelperImpl_storeSharedClassImpl_Entry (env , helperID );
1346
1379
@@ -1373,13 +1406,21 @@ Java_com_ibm_oti_shared_SharedClassURLHelperImpl_storeSharedClassImpl3(JNIEnv* e
1373
1406
if (!getStringChars (env , & partitionChars , & partitionLen , partitionObj )) {
1374
1407
goto _errorPostPathProtocol ;
1375
1408
}
1376
- if (!(cpeType = getCpeTypeForProtocol ((char * )urlElements .protocolChars , urlElements .protocolLen , urlElements .pathChars , urlElements .pathLen ))) {
1409
+ cpeType = getCpeTypeForProtocol (
1410
+ env ,
1411
+ urlElements .protocolChars ,
1412
+ urlElements .protocolLen ,
1413
+ urlElements .pathChars ,
1414
+ urlElements .pathLen ,
1415
+ & correctedPath );
1416
+ if (CPE_TYPE_UNKNOWN == cpeType ) {
1377
1417
goto _errorPostPartition ;
1378
1418
}
1379
1419
1380
1420
omrthread_monitor_enter (jclCacheMutex );
1381
1421
1382
- if (!(urlEntry = getCachedURL (env , helperID , urlElements .pathChars , urlElements .pathLen , cpeType , cpeStatus ))) {
1422
+ urlEntry = getCachedURL (env , helperID , urlElements .pathChars , urlElements .pathLen , cpeType , cpeStatus , correctedPath );
1423
+ if (NULL == urlEntry ) {
1383
1424
omrthread_monitor_exit (jclCacheMutex );
1384
1425
goto _errorPostPartition ;
1385
1426
}
@@ -2526,15 +2567,15 @@ runCorrectURLUnitTests(JNIEnv* env)
2526
2567
testCorrectURLPath (env , "///C:/dir%201/dir%202/dir%20%203/" , "C:\\dir 1\\dir 2\\dir 3" );
2527
2568
testCorrectURLPath (env , "//UNCTest/subdir" , "\\\\UNCTest\\subdir" );
2528
2569
testCorrectURLPath (env , "//UNCTest/sub%20dir" , "\\\\UNCTest\\sub dir" );
2529
- #else
2570
+ #else /* defined(WIN32) */
2530
2571
testCorrectURLPath (env , "/dir1" , "/dir1" );
2531
2572
testCorrectURLPath (env , "/dir1/" , "/dir1" );
2532
2573
testCorrectURLPath (env , "//dir1/" , "//dir1" );
2533
2574
testCorrectURLPath (env , "/dir%201" , "/dir 1" );
2534
2575
testCorrectURLPath (env , "/dir%251" , "/dir%1" );
2535
2576
testCorrectURLPath (env , "/dir%201/" , "/dir 1" );
2536
2577
testCorrectURLPath (env , "/dir%201/dir%202/dir%20%203/" , "/dir 1/dir 2/dir 3" );
2537
- #endif /* WIN32 */
2578
+ #endif /* defined( WIN32) */
2538
2579
}
2539
2580
2540
2581
#endif /* J9SHR_UNIT_TEST */
0 commit comments