Changeset 33930 for main/trunk


Ignore:
Timestamp:
2020-02-15T19:00:05+13:00 (4 years ago)
Author:
davidb
Message:

Code used to assume that major number was a single digit, as in 1.6 or 1.8. Now we have JDK 1.10 and above, and that the way version numbers are displayed has dropped the first part (the era), then search4j code needed to be updated to allow for this

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/search4j/libsearch4j.cpp

    r32880 r33930  
    176176bool Jvm::setVersionFromString( string version ) {
    177177    era_ = atoi( version.substr(0,1).c_str() );
    178     major_ = atoi( version.substr(2,1).c_str() );
    179     if(version.length() >= 5) {
    180       minor_ = atoi( version.substr(4,1).c_str() );
    181     } else {
    182       minor_ = 0;
    183     }
    184     if(version.length() >= 7) {
    185       update_ = atoi( version.substr(6,2).c_str() );
    186     } else {
    187       update_ = 0;
    188     }
     178    if (version[3] == '.') {
     179      // Parsing something like 1.8.0_24
     180      major_ = atoi( version.substr(2,1).c_str() );
     181      if(version.length() >= 5) {
     182        minor_ = atoi( version.substr(4,1).c_str() );
     183      } else {
     184        minor_ = 0;
     185      }
     186      if(version.length() >= 7) {
     187        update_ = atoi( version.substr(6,2).c_str() );
     188      } else {
     189        update_ = 0;
     190      }
     191    }
     192    else {
     193      // Parsing something like 1.8.0_242
     194      major_ = atoi( version.substr(2,2).c_str() );
     195      if(version.length() >= 6) {
     196        minor_ = atoi( version.substr(5,1).c_str() );
     197      } else {
     198        minor_ = 0;
     199      }
     200      if(version.length() >= 8) {
     201        update_ = atoi( version.substr(7,2).c_str() );
     202      } else {
     203        update_ = 0;
     204      }
     205     
     206    }
     207   
    189208    return true;
    190209}
    191210
    192211int Jvm::compare( Jvm otherJvm ) {
    193     //era
     212    //era 
    194213    if ( era_ > otherJvm.getEra() )
    195214        return 1;
     
    247266        const int to_match_len = 8;
    248267        if ( strcmp( output.substr( caret, to_match_len ).c_str() , " version" ) == 0 ) {
    249           era_ = atoi( output.substr(caret + to_match_len + 2,1).c_str() );
    250           major_ = atoi( output.substr(caret + to_match_len + 4,1).c_str() );
    251           minor_ = atoi( output.substr(caret + to_match_len + 6,1).c_str() );
    252           update_ = atoi( output.substr(caret + to_match_len + 8,2).c_str() );
     268          if (output[caret+to_match_len+3] == '.') {
     269        // Version of the form 1.8.0_24
     270        era_ = atoi( output.substr(caret + to_match_len + 2,1).c_str() );
     271        major_ = atoi( output.substr(caret + to_match_len + 4,1).c_str() );
     272        minor_ = atoi( output.substr(caret + to_match_len + 6,1).c_str() );
     273        update_ = atoi( output.substr(caret + to_match_len + 8,2).c_str() );
     274          }
     275          else {
     276        // Version of the form 11.0.6
     277        era_ = 1;
     278        major_ = atoi( output.substr(caret + to_match_len + 2,2).c_str() );
     279        minor_ = atoi( output.substr(caret + to_match_len + 5,1).c_str() );
     280        update_ = atoi( output.substr(caret + to_match_len + 7,2).c_str() );
     281
     282          }
    253283          found = true;
    254284        }
Note: See TracChangeset for help on using the changeset viewer.