Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Got UnsupportedOperationException if methods of OASFilter return null #502

Closed
code-d opened this issue Oct 13, 2020 · 5 comments · Fixed by #513
Closed

Got UnsupportedOperationException if methods of OASFilter return null #502

code-d opened this issue Oct 13, 2020 · 5 comments · Fixed by #513
Assignees
Labels
bug Something isn't working
Milestone

Comments

@code-d
Copy link

code-d commented Oct 13, 2020

Got UnsupportedOperationException if methods of custom org.eclipse.microprofile.openapi.OASFilter impl return null

[error]: Build step io.quarkus.smallrye.openapi.deployment.SmallRyeOpenApiProcessor#build threw an exception: java.lang.UnsupportedOperationException
	at java.base/java.util.Collections$UnmodifiableMap.remove(Collections.java:1460)
	at io.smallrye.openapi.api.util.FilterUtil.filterSchemas(FilterUtil.java:443)
	at io.smallrye.openapi.api.util.FilterUtil.filterComponents(FilterUtil.java:67)
	at io.smallrye.openapi.api.util.FilterUtil.applyFilter(FilterUtil.java:45)
	at io.smallrye.openapi.api.OpenApiDocument.filterModel(OpenApiDocument.java:168)
	at io.smallrye.openapi.api.OpenApiDocument.initialize(OpenApiDocument.java:128)
	at io.quarkus.smallrye.openapi.deployment.SmallRyeOpenApiProcessor.loadDocument(SmallRyeOpenApiProcessor.java:471)
	at io.quarkus.smallrye.openapi.deployment.SmallRyeOpenApiProcessor.build(SmallRyeOpenApiProcessor.java:282)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
	at io.quarkus.deployment.ExtensionLoader$2.execute(ExtensionLoader.java:936)
	at io.quarkus.builder.BuildContext.run(BuildContext.java:277)
	at org.jboss.threads.ContextClassLoaderSavingRunnable.run(ContextClassLoaderSavingRunnable.java:35)
	at org.jboss.threads.EnhancedQueueExecutor.safeRun(EnhancedQueueExecutor.java:2046)
	at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.doRunTask(EnhancedQueueExecutor.java:1578)
	at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1452)
	at java.base/java.lang.Thread.run(Thread.java:834)
	at org.jboss.threads.JBossThread.run(JBossThread.java:479)

io.smallrye.openapi.api.util.FilterUtil class has bug

@phillip-kruger
Copy link
Member

Hi @code-d . Thanks for the issue. So are you trying to remove something from the generated Model ? Or why is the filter returning null ? Can you post a small reproducer ?

@MikeEdgar
Copy link
Member

I took a quick look at this one and I think it's because some places in FilterUtil are operating directly on the Maps returned from the OpenAPI interfaces. For example, filterCallbacks removes from the map of callbacks, but instead should be using Components#removeCallback (or whatever the other parent model is based on context, since each method may be called from several locations in the utility). Returning null from a filter method is the signal to remove it from the containing model.

private static void filterCallbacks(OASFilter filter, Map<String, Callback> models) {
if (models != null) {
Collection<String> keys = new ArrayList<>(models.keySet());
for (String key : keys) {
Callback model = models.get(key);
filterCallback(filter, model);
if (filter.filterCallback(model) == null) {
models.remove(key);
}
}
}
}

@MikeEdgar MikeEdgar added the bug Something isn't working label Oct 13, 2020
@phillip-kruger
Copy link
Member

Thanks @MikeEdgar - that sounds fixable.

@phillip-kruger
Copy link
Member

@MikeEdgar - are you looking at this ?

@MikeEdgar
Copy link
Member

@MikeEdgar - are you looking at this ?

@phillip-kruger I haven't started anything yet. I might not have time until late this week.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants