Skip to content

Commit 55a5e0a

Browse files
authored
Fix NPE in LangServ while generating environment (#1237)
Fix NPE in LangServ while generating the environment without having a profiles file in the MethodScript directory. This fix creates an empty ProfilesImpl, such that any usage of the Profiles object will simply be like if the profiles file were empty.
1 parent 60f238b commit 55a5e0a

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

src/main/java/com/laytonsmith/core/ProfilesImpl.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,14 @@ public class ProfilesImpl implements Profiles {
2525
private static Map<String, Class<? extends Profile>> profileTypes = null;
2626

2727
/**
28-
*
28+
* Creates a new empty {@link Profiles}.
29+
*/
30+
public ProfilesImpl() {
31+
this.document = null;
32+
}
33+
34+
/**
35+
* Creates a new {@link Profiles}, initialized with profiles present in the given xml string.
2936
* @param xml
3037
* @throws InvalidProfileException
3138
*/
@@ -39,7 +46,7 @@ public ProfilesImpl(String xml) throws InvalidProfileException {
3946
}
4047

4148
/**
42-
*
49+
* Creates a new {@link Profiles}, initialized with profiles present in the given xml file.
4350
* @param profileFile
4451
* @throws IOException
4552
* @throws InvalidProfileException
@@ -49,7 +56,7 @@ public ProfilesImpl(File profileFile) throws IOException, InvalidProfileExceptio
4956
}
5057

5158
/**
52-
*
59+
* Creates a new {@link Profiles}, initialized with profiles present in the given xml stream.
5360
* @param profileData
5461
* @throws IOException
5562
* @throws InvalidProfileException

src/main/java/com/laytonsmith/core/Static.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1323,10 +1323,9 @@ public static Environment GenerateStandaloneEnvironment(
13231323
}
13241324
ConnectionMixinFactory.ConnectionMixinOptions options = new ConnectionMixinFactory.ConnectionMixinOptions();
13251325
options.setWorkingDirectory(platformFolder);
1326-
Profiles profiles = null;
1327-
if(MethodScriptFileLocations.getDefault().getProfilesFile().exists()) {
1328-
profiles = new ProfilesImpl(MethodScriptFileLocations.getDefault().getProfilesFile());
1329-
}
1326+
Profiles profiles = (MethodScriptFileLocations.getDefault().getProfilesFile().exists()
1327+
? new ProfilesImpl(MethodScriptFileLocations.getDefault().getProfilesFile())
1328+
: new ProfilesImpl());
13301329
PersistenceNetwork persistenceNetwork = new PersistenceNetworkImpl(MethodScriptFileLocations.getDefault().getPersistenceConfig(),
13311330
new URI(URLEncoder.encode("sqlite://" + new File(platformFolder, "persistence.db").getCanonicalPath().replace('\\', '/'), "UTF-8")), options);
13321331
GlobalEnv gEnv = new GlobalEnv(new MethodScriptExecutionQueue("MethodScriptExecutionQueue", "default"),

0 commit comments

Comments
 (0)