Hello everyone.

I have a problem regarding an odd error in the configuration admin. My
bundle exposes a metatype with a number of attributes, all of them with
cardinality 0 and types of long, integer and short.

I realize that I am using Karaf, but the stacktrace seems to point towards
Felix, so here goes:

When i register the metatype service and attempt to open the configuration
in the webconsole configuration admin, an error window opens:
AJAX Errorose <http://localhost:8181/system/console/configMgr#>
The request failed:

{"pid":"WrapperTypes","title":"WrapperTypes","description":"","properties":{"Long":{"name":"Long","optional":false,"is_set":false,"type":2


When i open the log, i see this exception:

2017-10-22T12:08:36,379 | WARN  | qtp514495649-120 | custom
           | 86 - org.eclipse.jetty.util - 9.3.14.v20161028 |
%configMgr.pluginTitle: Error reading configuration PID WrapperTypes
java.lang.ArrayIndexOutOfBoundsException: null
at java.lang.reflect.Array.get(Native Method) ~[?:?]
at org.apache.felix.webconsole.internal.configuration.MetaTypeSupport.
attributeToJson(MetaTypeSupport.java:145) [63:org.apache.karaf.
webconsole.console:4.1.2]
at org.apache.felix.webconsole.internal.configuration.
MetaTypeServiceSupport.mergeWithMetaType(MetaTypeServiceSupport.java:291)
[63:org.apache.karaf.webconsole.console:4.1.2]
at org.apache.felix.webconsole.internal.configuration.
ConfigAdminSupport.configForm(ConfigAdminSupport.java:407)
[63:org.apache.karaf.webconsole.console:4.1.2]
at org.apache.felix.webconsole.internal.configuration.ConfigAdminSupport.
printConfigurationJson(ConfigAdminSupport.java:357) [63:org.apache.karaf.
webconsole.console:4.1.2]
at 
org.apache.felix.webconsole.internal.configuration.ConfigManager.doPost(ConfigManager.java:203)
[63:org.apache.karaf.webconsole.console:4.1.2]
at 
org.apache.felix.webconsole.internal.configuration.ConfigManager.doGet(ConfigManager.java:215)
[63:org.apache.karaf.webconsole.console:4.1.2]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:687)
[13:javax.servlet-api:3.1.0]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
[13:javax.servlet-api:3.1.0]
at 
org.apache.felix.webconsole.internal.servlet.OsgiManager.service(OsgiManager.java:563)
[63:org.apache.karaf.webconsole.console:4.1.2]
at 
org.apache.felix.webconsole.internal.servlet.KarafOsgiManager.doService(KarafOsgiManager.java:78)
[63:org.apache.karaf.webconsole.console:4.1.2]
at 
org.apache.felix.webconsole.internal.servlet.KarafOsgiManager$1.run(KarafOsgiManager.java:58)
[63:org.apache.karaf.webconsole.console:4.1.2]
at java.security.AccessController.doPrivileged(Native Method) ~[?:?]
at org.apache.karaf.util.jaas.JaasHelper.doAs(JaasHelper.java:121)
[63:org.apache.karaf.webconsole.console:4.1.2]
at 
org.apache.felix.webconsole.internal.servlet.KarafOsgiManager.service(KarafOsgiManager.java:56)
[63:org.apache.karaf.webconsole.console:4.1.2]
at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:845)
[84:org.eclipse.jetty.servlet:9.3.14.v20161028]
at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:584)
[84:org.eclipse.jetty.servlet:9.3.14.v20161028]
at org.ops4j.pax.web.service.jetty.internal.HttpServiceServletHandler.
doHandle(HttpServiceServletHandler.java:71) [114:org.ops4j.pax.web.pax-
web-jetty:6.0.6]
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:143)
[83:org.eclipse.jetty.server:9.3.14.v20161028]
at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:548)
[81:org.eclipse.jetty.security:9.3.14.v20161028]
at org.eclipse.jetty.server.session.SessionHandler.
doHandle(SessionHandler.java:226) [83:org.eclipse.jetty.server:
9.3.14.v20161028]
at org.eclipse.jetty.server.handler.ContextHandler.
doHandle(ContextHandler.java:1180) [83:org.eclipse.jetty.server:
9.3.14.v20161028]
at 
org.ops4j.pax.web.service.jetty.internal.HttpServiceContext.doHandle(HttpServiceContext.java:284)
[114:org.ops4j.pax.web.pax-web-jetty:6.0.6]
at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:512)
[84:org.eclipse.jetty.servlet:9.3.14.v20161028]
at org.eclipse.jetty.server.session.SessionHandler.
doScope(SessionHandler.java:185) [83:org.eclipse.jetty.server:
9.3.14.v20161028]
at org.eclipse.jetty.server.handler.ContextHandler.
doScope(ContextHandler.java:1112) [83:org.eclipse.jetty.server:
9.3.14.v20161028]
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)
[83:org.eclipse.jetty.server:9.3.14.v20161028]
at org.ops4j.pax.web.service.jetty.internal.JettyServerHandlerCollection.
handle(JettyServerHandlerCollection.java:80) [114:org.ops4j.pax.web.pax-
web-jetty:6.0.6]
at 
org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:134)
[83:org.eclipse.jetty.server:9.3.14.v20161028]
at org.eclipse.jetty.server.Server.handle(Server.java:534)
[83:org.eclipse.jetty.server:9.3.14.v20161028]
at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:320)
[83:org.eclipse.jetty.server:9.3.14.v20161028]
at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:251)
[83:org.eclipse.jetty.server:9.3.14.v20161028]
at 
org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:273)
[75:org.eclipse.jetty.io:9.3.14.v20161028]
at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:95)
[75:org.eclipse.jetty.io:9.3.14.v20161028]
at 
org.eclipse.jetty.io.SelectChannelEndPoint$2.run(SelectChannelEndPoint.java:93)
[75:org.eclipse.jetty.io:9.3.14.v20161028]
at org.eclipse.jetty.util.thread.strategy.ExecuteProduceConsume.
executeProduceConsume(ExecuteProduceConsume.java:303)
[86:org.eclipse.jetty.util:9.3.14.v20161028]
at org.eclipse.jetty.util.thread.strategy.ExecuteProduceConsume.
produceConsume(ExecuteProduceConsume.java:148) [86:org.eclipse.jetty.util:9.
3.14.v20161028]
at org.eclipse.jetty.util.thread.strategy.ExecuteProduceConsume.run(
ExecuteProduceConsume.java:136) [86:org.eclipse.jetty.util:9.3.14.v20161028]
at 
org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:671)
[86:org.eclipse.jetty.util:9.3.14.v20161028]
at 
org.eclipse.jetty.util.thread.QueuedThreadPool$2.run(QueuedThreadPool.java:589)
[86:org.eclipse.jetty.util:9.3.14.v20161028]
at java.lang.Thread.run(Thread.java:745) [?:?]


I have tracked it to the following line in MetaTypeSupport:
value = Array.get( value, 0 );

When create a unit test and try some different values i cannot recreate the
error
Array.get( "", 0 )
Array.get( null, 0 )
Array.get( new String[0], 0 )

None of those calls creates that error:
java.lang.ArrayIndexOutOfBoundsException: null

The error occurs if there is no configuration file, or if the configuration
file exists but does not contain all the configuration items.

If i actually add the WrapperTypes.cfg configuration file with all the
configuration items defined, the exception does not occur when i open the
configuration window in the webconsole and I can edit the configuration as
desired.


Can anyone shed some light over what on earth happens? I can't see why this
happens? The code seems to imply that if cardinality is 0, the default
value should have been an empty string:

else if ( ad.getCardinality() == 0 )
{
value = ""; //$NON-NLS-1$
}
and the value should just be set
if ( ad.getCardinality() == 0 )
{
// scalar
if ( isPassword )
{
value = PASSWORD_PLACEHOLDER_VALUE;
}
else if ( value instanceof Vector )
{
value = ( ( Vector ) value ).get( 0 );
}
else if ( value.getClass().isArray() )
{
value = Array.get( value, 0 );
}
json.key( "value" ); //$NON-NLS-1$
json.value( value );
} But why on earth do i end up with a value that seems to be an array? Even
if i attempt do not give it a configuration, the error still occures, so i
don't see what i'm doing wrong?

Thanks in advance

-Martin

Reply via email to