Skip to content

Commit 30324ab

Browse files
Treiblesschorlegselzer
authored andcommitted
Reject Op not declaring a name during op discovery
1 parent 7dcb300 commit 30324ab

2 files changed

Lines changed: 17 additions & 5 deletions

File tree

src/main/java/org/scijava/ops/OpService.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,14 +125,19 @@ public void initOpCache() {
125125
}
126126

127127
private void addToCache(OpInfo opInfo, String opNames) {
128+
String[] parsedOpNames = OpUtils.parseOpNames(opNames);
129+
if (parsedOpNames == null || parsedOpNames.length == 0) {
130+
log.error("Skipping Op " + opInfo.implementationName() + ":\n"
131+
+ "Op implementation must provide name.");
132+
return;
133+
}
128134
if (!opInfo.isValid()) {
129135
log.error("Skipping invalid Op " + opInfo.implementationName() + ":\n"
130136
+ opInfo.getValidityException().getMessage());
131137
return;
132138
}
133-
String[] parsedNames = OpUtils.parseOpNames(opNames);
134-
addAliases(parsedNames, opInfo.implementationName());
135-
opCache.add(new PrefixQuery(parsedNames[0]), opInfo);
139+
addAliases(parsedOpNames, opInfo.implementationName());
140+
opCache.add(new PrefixQuery(parsedOpNames[0]), opInfo);
136141
}
137142

138143
@Override

src/main/java/org/scijava/ops/OpUtils.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,15 @@ public static String[] parseOpNames(String names) {
108108
* @return
109109
*/
110110
public static String[] parseOpName(String name) {
111-
String[] split = name.split("\\.");
112-
return new String[] { name, split[split.length - 1] };
111+
if (name == null || name.isEmpty()) {
112+
return new String[]{};
113+
}
114+
if (name.contains(".")) {
115+
String[] split = name.split("\\.");
116+
return new String[] { name, split[split.length - 1] };
117+
} else {
118+
return new String[]{name};
119+
}
113120
}
114121

115122
public static List<MemberInstance<?>> inputs(StructInstance<?> op) {

0 commit comments

Comments
 (0)