Uploaded image for project: 'PUBLIC - Liferay Portal Community Edition'
  1. PUBLIC - Liferay Portal Community Edition
  2. LPS-112226

Service-builder generates Code that will cause an NPE in the toCacheModel method when using optional Integer or Long fields.

    Details

      Description

      Reproduction:
      1. Create a service-builder module, e.g. service-builder-npe
      2. Edit service.xml, define an Integer or Long column besides the primary key. For example, you only need the following fields:

      <?xml version="1.0"?>
      <!DOCTYPE service-builder PUBLIC "-//Liferay//DTD Service Builder 7.1.0//EN" "http://www.liferay.com/dtd/liferay-service-builder_7_1_0.dtd">
      
      <service-builder  package-path="service.builder.npe">
      	<namespace>FOO</namespace>
      	<entity local-service="true" name="Foo" remote-service="true" uuid="true">
      
      		<!-- PK fields -->
      
      		<column name="fooId" primary="true" type="long" />
      
      		<column name="nullableInteger" type="Integer" />
      		<column name="nullableLong" type="Long" />
      
      	</entity>
      </service-builder>
      

      3. Run buildService task, then build the api and service
      4. Deploy the modules
      5. Go to Control Panel - Server Admin - scripts, and execute the following Groovy script, which adds a new foo entity:

      import com.liferay.counter.kernel.service.CounterLocalServiceUtil;
      import service.builder.npe.model.Foo;
      import service.builder.npe.service.FooLocalServiceUtil;
      
      long primaryKey = CounterLocalServiceUtil.increment(Foo.class.getName());
      Foo foo = FooLocalServiceUtil.createFoo(primaryKey);
      try{FooLocalServiceUtil.addFoo(foo);}
      catch(Exception e){e.printStackTrace();}
      

      Result: An NPE is thrown:

      java.lang.NullPointerException
      	at service.builder.npe.model.impl.FooModelImpl.toCacheModel(FooModelImpl.java:552)
      

        Attachments

          Activity

            People

            • Assignee:
              summer.zhang Summer Zhang
              Reporter:
              laszlo.hudak Laszlo Hudak
              Participants of an Issue:
              Recent user:
              Summer Zhang
              Engineering Assignee:
              Laszlo Hudak
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Days since last comment:
                12 weeks, 4 days ago

                Packages

                Version Package
                7.0.X
                7.1.X
                7.2.X
                Master