fix: The field connection with type URLConnection is not Serializable. (#2034)

An allegedly Serializable object with non-transient, non-serializable data members could cause program crashes. Method toURL() of URL class is depreceted.
This commit is contained in:
Ilya Ksenofontov 2020-12-09 21:33:31 +03:00 committed by GitHub
parent 3235dc2fec
commit eedf0ac1af
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -15,7 +15,7 @@ import org.rythmengine.resource.TemplateResourceBase;
*/
public class StreamTemplateResource extends TemplateResourceBase {
private final String path;
private URLConnection connection = null;
private transient URLConnection connection = null;
public StreamTemplateResource(String path, StreamResourceLoader loader) {
super(loader);
@ -32,7 +32,7 @@ public class StreamTemplateResource extends TemplateResourceBase {
try {
final File rythm = new File(path);
if (rythm.exists()) {
connection = rythm.toURL().openConnection();
connection = rythm.toURI().toURL().openConnection();
}
} catch (IOException ex) {
throw new RuntimeException("Get template resource failed", ex);