@@ -135,47 +135,51 @@ public static Lang loadFromResource(final String languageRulesResourceName, fina
135135 }
136136
137137 final Scanner scanner = new Scanner (lRulesIS , ResourceConstants .ENCODING );
138- boolean inExtendedComment = false ;
139- while (scanner .hasNextLine ()) {
140- final String rawLine = scanner .nextLine ();
141- String line = rawLine ;
142- if (inExtendedComment ) {
143- // check for closing comment marker, otherwise discard doc comment line
144- if (line .endsWith (ResourceConstants .EXT_CMT_END )) {
145- inExtendedComment = false ;
146- }
147- } else {
148- if (line .startsWith (ResourceConstants .EXT_CMT_START )) {
149- inExtendedComment = true ;
150- } else {
151- // discard comments
152- final int cmtI = line .indexOf (ResourceConstants .CMT );
153- if (cmtI >= 0 ) {
154- line = line .substring (0 , cmtI );
155- }
156-
157- // trim leading-trailing whitespace
158- line = line .trim ();
159-
160- if (line .length () == 0 ) {
161- continue ; // empty lines can be safely skipped
138+ try {
139+ boolean inExtendedComment = false ;
140+ while (scanner .hasNextLine ()) {
141+ final String rawLine = scanner .nextLine ();
142+ String line = rawLine ;
143+ if (inExtendedComment ) {
144+ // check for closing comment marker, otherwise discard doc comment line
145+ if (line .endsWith (ResourceConstants .EXT_CMT_END )) {
146+ inExtendedComment = false ;
162147 }
163-
164- // split it up
165- final String [] parts = line .split ("\\ s+" );
166-
167- if (parts .length != 3 ) {
168- throw new IllegalArgumentException ("Malformed line '" + rawLine + "' in language resource '" +
169- languageRulesResourceName + "'" );
148+ } else {
149+ if (line .startsWith (ResourceConstants .EXT_CMT_START )) {
150+ inExtendedComment = true ;
151+ } else {
152+ // discard comments
153+ final int cmtI = line .indexOf (ResourceConstants .CMT );
154+ if (cmtI >= 0 ) {
155+ line = line .substring (0 , cmtI );
156+ }
157+
158+ // trim leading-trailing whitespace
159+ line = line .trim ();
160+
161+ if (line .length () == 0 ) {
162+ continue ; // empty lines can be safely skipped
163+ }
164+
165+ // split it up
166+ final String [] parts = line .split ("\\ s+" );
167+
168+ if (parts .length != 3 ) {
169+ throw new IllegalArgumentException ("Malformed line '" + rawLine
170+ + "' in language resource '" + languageRulesResourceName + "'" );
171+ }
172+
173+ final Pattern pattern = Pattern .compile (parts [0 ]);
174+ final String [] langs = parts [1 ].split ("\\ +" );
175+ final boolean accept = parts [2 ].equals ("true" );
176+
177+ rules .add (new LangRule (pattern , new HashSet <String >(Arrays .asList (langs )), accept ));
170178 }
171-
172- final Pattern pattern = Pattern .compile (parts [0 ]);
173- final String [] langs = parts [1 ].split ("\\ +" );
174- final boolean accept = parts [2 ].equals ("true" );
175-
176- rules .add (new LangRule (pattern , new HashSet <String >(Arrays .asList (langs )), accept ));
177179 }
178180 }
181+ } finally {
182+ scanner .close ();
179183 }
180184 return new Lang (rules , languages );
181185 }
0 commit comments