Bug 858286

Summary: Runtime Error For input string: "zero" at java.lang.NumberFormatException.forInputString:65
Product: [Community] Candlepin Reporter: John Sefler <jsefler>
Component: candlepinAssignee: William Poteat <wpoteat>
Status: CLOSED CURRENTRELEASE QA Contact: Katello QA List <katello-qa-list>
Severity: medium Docs Contact:
Priority: unspecified    
Version: 0.9CC: bkearney, skallesh, wpoteat
Target Milestone: ---Keywords: Regression
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2013-10-01 13:50:49 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On:    
Bug Blocks: 840995, 863175, 920191    

Description John Sefler 2012-09-18 14:50:54 UTC
Description of problem:
After creating a product with a socket attribute value="zero" (Note this is a String) and then creating a subscription for it and trying to consume it, I get a runtime error from candlepin.

This is a regression.  Candlepin has tolerated a string value for the sockets attribute for the past many releases.  Effectively candlepin has just ignored a non-numeric sockets value treating it as if it did not exist.


Version-Release number of selected component (if applicable):
[root@jsefler-f14-candlepin util]# git show-ref | grep master
63dbb3b0f6c9e0181475f869ae1050d428d02caa refs/heads/master
63dbb3b0f6c9e0181475f869ae1050d428d02caa refs/remotes/origin/master


How reproducible:
Creation of this offending product/subscription is part of our automated test suite under the ListTests.


Steps to Reproduce:
[root@jsefler-rhel59 ~]# subscription-manager list --avail | grep zero -A1
Subscription Name:    	Awesome OS for systems with sockets value="zero"
SKU:                  	zero-sockets
Pool Id:              	8a90f81d39d982480139d98b16b40a87
[root@jsefler-rhel59 ~]# subscription-manager subscribe --pool 8a90f81d39d982480139d98b16b40a87
Runtime Error For input string: "zero" at java.lang.NumberFormatException.forInputString:65

^^ BANG!


Additional info:
[root@jsefler-f14-candlepin ~]# tail -f /var/log/tomcat6/catalina.out

Sep 18 10:23:18 [http-8443-1] INFO  org.candlepin.resource.ConsumerResource - Consumer 3b5b2cf4-5c86-4c03-9cec-b847f1d5ad9e updated.
Sep 18 10:23:19 [http-8443-1] ERROR org.candlepin.exceptions.mappers.CandlepinExceptionMapper - Runtime Error For input string: "zero" at java.lang.NumberFormatException.forInputString:65
java.lang.NumberFormatException: For input string: "zero"
	at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
	at java.lang.Integer.parseInt(Integer.java:481)
	at java.lang.Integer.<init>(Integer.java:636)
	at org.candlepin.util.X509V3ExtensionUtil.createSubscription(X509V3ExtensionUtil.java:195)
	at org.candlepin.util.X509V3ExtensionUtil.createEntitlementBody(X509V3ExtensionUtil.java:158)
	at org.candlepin.util.X509V3ExtensionUtil.createEntitlementDataPayload(X509V3ExtensionUtil.java:121)
	at org.candlepin.service.impl.DefaultEntitlementCertServiceAdapter.generateEntitlementCert(DefaultEntitlementCertServiceAdapter.java:328)
	at org.candlepin.service.impl.DefaultEntitlementCertServiceAdapter.generateEntitlementCert(DefaultEntitlementCertServiceAdapter.java:108)
	at org.candlepin.controller.CandlepinPoolManager.generateEntitlementCertificate(CandlepinPoolManager.java:579)
	at org.candlepin.controller.CandlepinPoolManager.addEntitlement(CandlepinPoolManager.java:521)
	at org.candlepin.controller.CandlepinPoolManager.entitleByPool(CandlepinPoolManager.java:470)
	at com.google.inject.persist.jpa.JpaLocalTxnInterceptor.invoke(JpaLocalTxnInterceptor.java:66)
	at org.candlepin.controller.Entitler.createEntitlementByPool(Entitler.java:92)
	at org.candlepin.controller.Entitler.bindByPool(Entitler.java:84)
	at org.candlepin.resource.ConsumerResource.bind(ConsumerResource.java:1248)
	at org.candlepin.auth.interceptor.SecurityInterceptor.invoke(SecurityInterceptor.java:120)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:616)
	at org.jboss.resteasy.core.MethodInjectorImpl.invoke(MethodInjectorImpl.java:155)
	at org.jboss.resteasy.core.ResourceMethod.invokeOnTarget(ResourceMethod.java:257)
	at org.jboss.resteasy.core.ResourceMethod.invoke(ResourceMethod.java:222)
	at org.jboss.resteasy.core.ResourceMethod.invoke(ResourceMethod.java:211)
	at org.jboss.resteasy.core.SynchronousDispatcher.getResponse(SynchronousDispatcher.java:525)
	at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:502)
	at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:119)
	at org.jboss.resteasy.plugins.server.servlet.ServletContainerDispatcher.service(ServletContainerDispatcher.java:208)
	at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:55)
	at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:50)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
	at com.google.inject.servlet.ServletDefinition.doService(ServletDefinition.java:263)
	at com.google.inject.servlet.ServletDefinition.service(ServletDefinition.java:178)
	at com.google.inject.servlet.ManagedServletPipeline.service(ManagedServletPipeline.java:91)
	at com.google.inject.servlet.FilterChainInvocation.doFilter(FilterChainInvocation.java:62)
	at org.candlepin.servlet.filter.ContentTypeHackFilter.doFilter(ContentTypeHackFilter.java:61)
	at com.google.inject.servlet.FilterDefinition.doFilter(FilterDefinition.java:163)
	at com.google.inject.servlet.FilterChainInvocation.doFilter(FilterChainInvocation.java:58)
	at org.candlepin.servlet.filter.logging.LoggingFilter.doFilter(LoggingFilter.java:60)
	at com.google.inject.servlet.FilterDefinition.doFilter(FilterDefinition.java:163)
	at com.google.inject.servlet.FilterChainInvocation.doFilter(FilterChainInvocation.java:58)
	at org.candlepin.servlet.filter.CandlepinPersistFilter.doFilter(CandlepinPersistFilter.java:48)
	at com.google.inject.servlet.FilterDefinition.doFilter(FilterDefinition.java:163)
	at com.google.inject.servlet.FilterChainInvocation.doFilter(FilterChainInvocation.java:58)
	at org.candlepin.servlet.filter.CandlepinScopeFilter.doFilter(CandlepinScopeFilter.java:57)
	at com.google.inject.servlet.FilterDefinition.doFilter(FilterDefinition.java:163)
	at com.google.inject.servlet.FilterChainInvocation.doFilter(FilterChainInvocation.java:58)
	at com.google.inject.servlet.ManagedFilterPipeline.dispatch(ManagedFilterPipeline.java:118)
	at com.google.inject.servlet.GuiceFilter.doFilter(GuiceFilter.java:113)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
	at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:857)
	at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
	at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
	at java.lang.Thread.run(Thread.java:636)

Comment 1 James Bowes 2012-09-20 09:21:29 UTC
Fixed in candlepin master, 0.7.11

Comment 2 John Sefler 2012-09-23 01:14:01 UTC
(In reply to comment #1)
> Fixed in candlepin master, 0.7.11

Are you sure?  Problem still exists...

[root@jsefler-f14-candlepin candlepin]# git show-ref | grep master
d29c9b4a4f61f2db96f91b79630ee2f4c6568899 refs/heads/master

[root@jsefler-rhel59 ~]# subscription-manager version
registered to: 0.7.11-1
server type: subscription management service
subscription-manager: 1.0.19-1.git.11.b6e84e6.el5
python-rhsm: 1.0.8-1.git.1.b3f4b2c.el5

[root@jsefler-rhel59 ~]# subscription-manager list --avail | grep zero -A1
Subscription Name:    	Awesome OS for systems with sockets value="zero"
SKU:                  	zero-sockets
Pool Id:              	8a90f81d39f09f1c0139f0a5524e0a87

[root@jsefler-rhel59 ~]# subscription-manager subscribe --pool 8a90f81d39f09f1c0139f0a5524e0a87
Runtime Error For input string: "zero" at java.lang.NumberFormatException.forInputString:65


^^^ BANG! Problem still exists against latest pull from candlepin master.  

Moving back to ASSIGNED

Comment 3 James Bowes 2012-09-24 13:32:59 UTC
commit was 5c45eb4c

The behaviour should be back to what it was with certv3:
- A certv1 cert is loosely typed and will take most (all?) data, even if its not right (ie 'zero' sockets).
- A certv3 (or 2) cert is strongly typed. the cert itself will only take numeric values for the sockets value.

Your client's probably getting a certv3 cert, right? We could give a better error message, but really, the validation has to happen from whoever/whatever populates those values. Probably the IT adapter, or katello.

How about we log the problem in candlepin, then set in a default that would match what the certv1 client would have done?

Comment 4 John Sefler 2012-10-02 18:13:11 UTC
(In reply to comment #3)
> How about we log the problem in candlepin, then set in a default that would
> match what the certv1 client would have done?

The person who should really decide what is correct here is the person who decided that certv1 should be loosely typed.

Personally I believe that strongly typed attributes is the right approach and will prevent erroneously valued attributes from slipping through the cracks of an overly tolerant candlepin.  These types of bugs are hard to find.  Hence I vote "no" to logging the problem in candlepin and settting a default that would match what the certv1 client would have done.  If my vote counts, then a product with a socket attribute value="zero" (a String) is invalid and should throw an error somewhere (at least the candlepin log) and a pool that provides this product should not become available to the client.  Refresh pools should probably skip it and log it to the candlepin log.

Comment 5 William Poteat 2013-01-08 19:30:12 UTC
commit ebff18938b58a4ab87bc4b322f204b2ef45fa81b

Comment 6 William Poteat 2013-01-11 18:51:54 UTC
make that commit dcc2f2235fcf30c6db49ee512e24f3f78bdd89ce

Comment 7 Shwetha Kallesh 2013-04-22 09:44:50 UTC
Verified!!

[root@localhost ~]# subscription-manager version
server type: Red Hat Subscription Management
subscription management server: 0.8.4-1
subscription-manager: 1.8.6-1.el7
python-rhsm: 1.8.9-1.el7


[root@localhost ~]# subscription-manager list --avail | grep 'Zero socket test' -A6
Subscription Name: Zero socket test
SKU:               Zero-socket-product
Pool ID:           8ac6818a3e21268f013e2f82f36d42ed
Quantity:          20
Service Level:     
Service Type:      
Multi-Entitlement: No
[root@localhost ~]# subscription-manager attach --pool 8ac6818a3e21268f013e2f82f36d42ed
1 local certificate has been deleted.
Successfully attached a subscription for: Zero socket test
[root@localhost ~]# curl -k -u admin:admin https://10.70.35.193:8443/candlepin/pools/8ac6818a3e21268f013e2f82f36d42ed | python -mjson.tool | grep socket -A3
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  2453    0  2453    0     0  40815      0 --:--:-- --:--:-- --:--:-- 41576
            "productId": "Zero-socket-product", 
            "updated": "2013-04-22T02:11:51.277+0000", 
            "value": "ALL"
        }, 
--
            "productId": "Zero-socket-product", 
            "updated": "2013-04-22T02:11:51.278+0000", 
            "value": "server"
        }, 
--
            "name": "sockets", 
            "productId": "Zero-socket-product", 
            "updated": "2013-04-22T02:11:51.278+0000", 
            "value": "0"
        }, 
--
            "productId": "Zero-socket-product", 
            "updated": "2013-04-22T02:11:51.278+0000", 
            "value": "1.0"
        }, 
--
            "productId": "Zero-socket-product", 
            "updated": "2013-04-22T02:11:51.278+0000", 
            "value": "30"
        }, 
--
            "productId": "Zero-socket-product", 
            "updated": "2013-04-22T02:11:51.278+0000", 
            "value": "SVC"
        }
--
    "productId": "Zero-socket-product", 
    "productName": "Zero socket test", 
    "providedProducts": [
        {
            "created": "2013-04-22T02:11:51.278+0000",