@@ -72,6 +72,7 @@ export function parseProfile(document: vscode.TextDocument): ProfileContent {
7272 const profileSettings = new Map < string , string > ( ) ;
7373 let lastElement = undefined ;
7474 const diagnostics : vscode . Diagnostic [ ] = [ ] ;
75+ let settingsVersion = JavaConstants . CURRENT_FORMATTER_SETTINGS_VERSION ;
7576 const documentDOM = new DOMParser ( {
7677 locator : { } , errorHandler : ( _level , msg ) => {
7778 const bracketExp : RegExp = new RegExp ( "\\[line:(\\d*),col:(\\d*)\\]" , "g" ) ;
@@ -81,11 +82,13 @@ export function parseProfile(document: vscode.TextDocument): ProfileContent {
8182 }
8283 }
8384 } ) . parseFromString ( document . getText ( ) ) ;
84- let settingsVersion = documentDOM . documentElement . getAttribute ( "version" ) || JavaConstants . CURRENT_FORMATTER_SETTINGS_VERSION ;
85+ if ( ! documentDOM ) {
86+ return { isValid : false , settingsVersion, diagnostics } ;
87+ }
88+ settingsVersion = documentDOM . documentElement . getAttribute ( "version" ) || settingsVersion ;
8589 const profiles = documentDOM . documentElement . getElementsByTagName ( "profile" ) ;
8690 if ( ! profiles || profiles . length === 0 ) {
87- diagnostics . push ( new vscode . Diagnostic ( new vscode . Range ( new vscode . Position ( 0 , 0 ) , new vscode . Position ( 0 , 0 ) ) , "No valid profiles found." ) ) ;
88- return { settingsVersion, diagnostics } ;
91+ return { isValid : false , settingsVersion, diagnostics } ;
8992 }
9093 const settingsProfileName : string | undefined = vscode . workspace . getConfiguration ( "java" ) . get < string > ( JavaConstants . SETTINGS_PROFILE_KEY ) ;
9194 for ( let i = 0 ; i < profiles . length ; i ++ ) {
@@ -119,8 +122,7 @@ export function parseProfile(document: vscode.TextDocument): ProfileContent {
119122 }
120123 }
121124 if ( ! profileElements . size ) {
122- diagnostics . push ( new vscode . Diagnostic ( new vscode . Range ( new vscode . Position ( 0 , 0 ) , new vscode . Position ( 0 , 0 ) ) , "No valid settings found in the profile." ) ) ;
123- return { settingsVersion, diagnostics } ;
125+ return { isValid : false , settingsVersion, diagnostics } ;
124126 }
125127 const supportedProfileSettings = getSupportedProfileSettings ( Number ( settingsVersion ) ) ;
126128 for ( const setting of supportedProfileSettings . values ( ) ) {
@@ -146,6 +148,7 @@ export function parseProfile(document: vscode.TextDocument): ProfileContent {
146148 setting . value = webViewValue ;
147149 }
148150 return {
151+ isValid : true ,
149152 settingsVersion,
150153 diagnostics,
151154 profileElements,
0 commit comments