Skip to content

Commit 2225fd3

Browse files
Flossyclaude
andcommitted
Fix parameter validation in ApplicationDescriptorDTO, IsolatedClassLoader, and ServiceRegistryImpl
Issue #81: ApplicationDescriptorDTO permission conversion doesn't validate null fields - Location: toSecurityConfig() method - Problem: Created Permission objects without validating DTO fields are non-null - Fix: Added validation for path, host, actions, and permission names - Impact: Clear error messages instead of NPE when config has null values Issue #80: IsolatedClassLoader.create() doesn't validate parameters - Location: static factory method create() - Problem: No validation of applicationId, descriptor, or platformSharedLoader - Fix: Added Objects.requireNonNull() for all three parameters - Impact: Fails fast with clear message instead of NPE deep in factory method Issue #79: ServiceRegistryImpl methods don't validate parameters - Location: getService(), getAllServices(), unregisterService() - Problem: JavaDoc claimed NPE would be thrown but no validation present - Fix: Added Objects.requireNonNull() for all parameters - Impact: Contract fulfilled, clearer error messages All fixes follow defensive programming pattern: - Validate early (fail fast) - Clear error messages indicating which parameter was null - Consistent with existing validation patterns in codebase Fixes: #81, #80, #79 Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent 857349d commit 2225fd3

3 files changed

Lines changed: 26 additions & 0 deletions

File tree

jplatform-classloader/src/main/java/org/flossware/jplatform/classloader/IsolatedClassLoader.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import java.io.File;
99
import java.net.URI;
1010
import java.util.Map;
11+
import java.util.Objects;
1112

1213
/**
1314
* Platform-specific class loader for isolated application execution.
@@ -43,6 +44,9 @@ private IsolatedClassLoader(String applicationId,
4344
public static IsolatedClassLoader create(String applicationId,
4445
ApplicationDescriptor descriptor,
4546
ClassLoader platformSharedLoader) {
47+
Objects.requireNonNull(applicationId, "applicationId cannot be null");
48+
Objects.requireNonNull(descriptor, "descriptor cannot be null");
49+
Objects.requireNonNull(platformSharedLoader, "platformSharedLoader cannot be null");
4650

4751
ResourceTrackingListener tracker = new ResourceTrackingListener();
4852

jplatform-config/src/main/java/org/flossware/jplatform/config/ApplicationDescriptorDTO.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,18 +200,33 @@ public SecurityConfig toSecurityConfig() {
200200

201201
if (filePermissions != null) {
202202
for (FilePermissionDTO fp : filePermissions) {
203+
if (fp.path == null || fp.path.trim().isEmpty()) {
204+
throw new IllegalArgumentException("File permission path cannot be null or empty");
205+
}
206+
if (fp.actions == null || fp.actions.trim().isEmpty()) {
207+
throw new IllegalArgumentException("File permission actions cannot be null or empty");
208+
}
203209
builder.addFilePermission(new FilePermission(fp.path, fp.actions));
204210
}
205211
}
206212

207213
if (socketPermissions != null) {
208214
for (SocketPermissionDTO sp : socketPermissions) {
215+
if (sp.host == null || sp.host.trim().isEmpty()) {
216+
throw new IllegalArgumentException("Socket permission host cannot be null or empty");
217+
}
218+
if (sp.actions == null || sp.actions.trim().isEmpty()) {
219+
throw new IllegalArgumentException("Socket permission actions cannot be null or empty");
220+
}
209221
builder.addSocketPermission(new SocketPermission(sp.host, sp.actions));
210222
}
211223
}
212224

213225
if (runtimePermissions != null) {
214226
for (String rp : runtimePermissions) {
227+
if (rp == null || rp.trim().isEmpty()) {
228+
throw new IllegalArgumentException("Runtime permission name cannot be null or empty");
229+
}
215230
builder.addRuntimePermission(new RuntimePermission(rp));
216231
}
217232
}

jplatform-messaging/src/main/java/org/flossware/jplatform/messaging/ServiceRegistryImpl.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@ public <T> void registerService(Class<T> serviceInterface, T implementation) {
101101
*/
102102
@Override
103103
public <T> Optional<T> getService(Class<T> serviceInterface) {
104+
Objects.requireNonNull(serviceInterface, "serviceInterface cannot be null");
105+
104106
List<ServiceEntry> entries = services.get(serviceInterface);
105107

106108
if (entries == null || entries.isEmpty()) {
@@ -125,6 +127,8 @@ public <T> Optional<T> getService(Class<T> serviceInterface) {
125127
*/
126128
@Override
127129
public <T> List<T> getAllServices(Class<T> serviceInterface) {
130+
Objects.requireNonNull(serviceInterface, "serviceInterface cannot be null");
131+
128132
List<ServiceEntry> entries = services.get(serviceInterface);
129133

130134
if (entries == null || entries.isEmpty()) {
@@ -154,6 +158,9 @@ public <T> List<T> getAllServices(Class<T> serviceInterface) {
154158
*/
155159
@Override
156160
public void unregisterService(Class<?> serviceInterface, Object implementation) {
161+
Objects.requireNonNull(serviceInterface, "serviceInterface cannot be null");
162+
Objects.requireNonNull(implementation, "implementation cannot be null");
163+
157164
List<ServiceEntry> entries = services.get(serviceInterface);
158165

159166
if (entries != null) {

0 commit comments

Comments
 (0)