title: Save modified shape contents to PostGIS using Geotools fails with NullPointerException
body: <p>I am modifying a shape file and I want to save the modified version in the database using Geotools. However the code works fine till shapefile modification, but fails at the point of database setup.</p>
  
  <p>Here is the code:</p>
  
  <pre><code>FileDataStore ds = FileDataStoreFinder.getDataStore(new File("/abc.shp"));
          logger.debug("starting check");
          SimpleFeatureType schema = ds.getSchema();
          // create new schema
          SimpleFeatureTypeBuilder builder = new SimpleFeatureTypeBuilder();
          builder.setName(schema.getName());
          builder.setSuperType((SimpleFeatureType) schema.getSuper());
          builder.addAll(schema.getAttributeDescriptors());
          // add new attribute(s)
          builder.add("shapeID", String.class);
          // build new schema
          SimpleFeatureType nSchema = builder.buildFeatureType();
  
          logger.debug("Adding column attr to shpfile");
          // loop through features adding new attribute
          List&lt;SimpleFeature&gt; features = new ArrayList&lt;&gt;();
          try (SimpleFeatureIterator itr = ds.getFeatureSource().getFeatures().features()) {
              while (itr.hasNext()) {
                  SimpleFeature f = itr.next();
                  SimpleFeature f2 = DataUtilities.reType(nSchema, f);
                  f2.setAttribute("shapeID", "SHP1234");
                  System.out.println(f2);
                  features.add(f2);
              }
          }
          Properties params = new Properties();
         // Map&lt;String, Object&gt; params = new HashMap&lt;&gt;();
          params.put("user", "user1");
          params.put("passwd", "postgres");
          params.put("port", "5432");
          params.put("host", "127.0.0.1");
          params.put("database", "test");
          params.put("dbtype", "postgres");
          params.put(PostgisDataStoreFactory.LOOSEBBOX, true );
  
          logger.debug("Entering the critical point");
  
          DataStore dataStore = DataStoreFinder.getDataStore(params);
          SimpleFeatureSource source = dataStore.getFeatureSource("table_name"); //table name already present in PostGIS
  
          //dataStore.createSchema(nSchema);  //Creates a new table
  
          if (source instanceof SimpleFeatureStore) {
              SimpleFeatureStore store = (SimpleFeatureStore) source;
              store.addFeatures(DataUtilities.collection(features));
  
             logger.debug("Stored in database successfully");
          } else {
              logger.error("Unable to write to database");
          }
      }
  </code></pre>
  
  <p>The error stack trace is as follows.</p>
  
  <pre><code>2018-10-02 16:54:52 DEBUG Initmain:38 - starting check
  2018-10-02 16:54:56 DEBUG Initmain:41 - starting check
  2018-10-02 16:54:58 DEBUG Initmain:53 - Adding column attr to shpfile
  2018-10-02 16:54:58 DEBUG Initmain:75 - Entering the critical point
  Exception in thread "main" java.lang.NullPointerException
      at org.geotools.geoshapesave.saveShape.main(saveShape.java:78)
  ------------------------------------------------------------------------
  BUILD FAILURE
  ------------------------------------------------------------------------
  Total time: 16.638s
  Finished at: Tue Oct 02 16:55:00 CEST 2018
  Final Memory: 8M/76M
  ------------------------------------------------------------------------
  Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.2.1:exec (default-cli) on project GeoDemo: Command execution failed. Process exited with an error: 1 (Exit value: 1) -&gt; [Help 1]
  org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.2.1:exec (default-cli) on project GeoDemo: Command execution failed.
      at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:217)
      at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
      at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
      at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84)
      at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59)
      at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183)
      at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161)
      at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:320)
      at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:156)
      at org.apache.maven.cli.MavenCli.execute(MavenCli.java:537)
      at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:196)
      at org.apache.maven.cli.MavenCli.main(MavenCli.java:141)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:497)
      at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290)
      at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230)
      at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409)
      at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352)
  Caused by: org.apache.maven.plugin.MojoExecutionException: Command execution failed.
      at org.codehaus.mojo.exec.ExecMojo.execute(ExecMojo.java:362)
      at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:101)
      at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:209)
      ... 19 more
  Caused by: org.apache.commons.exec.ExecuteException: Process exited with an error: 1 (Exit value: 1)
      at org.apache.commons.exec.DefaultExecutor.executeInternal(DefaultExecutor.java:377)
      at org.apache.commons.exec.DefaultExecutor.execute(DefaultExecutor.java:160)
      at org.codehaus.mojo.exec.ExecMojo.executeCommandLine(ExecMojo.java:610)
      at org.codehaus.mojo.exec.ExecMojo.execute(ExecMojo.java:352)
      ... 21 more 
  </code></pre>
  
  <p>Also attaching the pom.xml based on the above stack trace inputs</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"&gt;
      &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
      &lt;groupId&gt;org.geotools&lt;/groupId&gt;
      &lt;artifactId&gt;GeoDemo&lt;/artifactId&gt;
      &lt;version&gt;1.0-SNAPSHOT&lt;/version&gt;
      &lt;packaging&gt;jar&lt;/packaging&gt;
     &lt;properties&gt;
          &lt;project.build.sourceEncoding&gt;UTF-8&lt;/project.build.sourceEncoding&gt;
          &lt;geotools.version&gt;20-SNAPSHOT&lt;/geotools.version&gt;
      &lt;/properties&gt;
      &lt;dependencies&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;junit&lt;/groupId&gt;
              &lt;artifactId&gt;junit&lt;/artifactId&gt;
              &lt;version&gt;4.12&lt;/version&gt;
              &lt;type&gt;jar&lt;/type&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;it.geosolutions&lt;/groupId&gt;
              &lt;artifactId&gt;geoserver-manager&lt;/artifactId&gt;
              &lt;version&gt;1.7.0&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.geotools&lt;/groupId&gt;
              &lt;artifactId&gt;gt-shapefile&lt;/artifactId&gt;
              &lt;version&gt;${geotools.version}&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.geotools&lt;/groupId&gt;
              &lt;artifactId&gt;gt-swing&lt;/artifactId&gt;
              &lt;version&gt;${geotools.version}&lt;/version&gt;
          &lt;/dependency&gt;
           &lt;dependency&gt;
              &lt;groupId&gt;org.geotools&lt;/groupId&gt;
              &lt;artifactId&gt;gt-jdbc&lt;/artifactId&gt;
              &lt;version&gt;${geotools.version}&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.geotools.jdbc&lt;/groupId&gt;
              &lt;artifactId&gt;gt-jdbc-postgis&lt;/artifactId&gt;
              &lt;version&gt;${geotools.version}&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
      &lt;groupId&gt;org.slf4j&lt;/groupId&gt;
      &lt;artifactId&gt;slf4j-log4j12&lt;/artifactId&gt;
      &lt;version&gt;1.5.6&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;javax.servlet&lt;/groupId&gt;
              &lt;artifactId&gt;javax.servlet-api&lt;/artifactId&gt;
              &lt;version&gt;4.0.1&lt;/version&gt;
              &lt;type&gt;jar&lt;/type&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.apache.httpcomponents&lt;/groupId&gt;
              &lt;artifactId&gt;httpclient&lt;/artifactId&gt;
              &lt;version&gt;4.5.5&lt;/version&gt;
              &lt;type&gt;jar&lt;/type&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;javax.servlet&lt;/groupId&gt;
              &lt;artifactId&gt;jstl&lt;/artifactId&gt;
              &lt;version&gt;1.2&lt;/version&gt;
              &lt;type&gt;jar&lt;/type&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.mortbay.jetty&lt;/groupId&gt;
              &lt;artifactId&gt;jsp-2.1&lt;/artifactId&gt;
              &lt;version&gt;6.1.6&lt;/version&gt;
              &lt;type&gt;jar&lt;/type&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.apache.ant&lt;/groupId&gt;
              &lt;artifactId&gt;ant&lt;/artifactId&gt;
              &lt;version&gt;1.10.1&lt;/version&gt;
              &lt;type&gt;jar&lt;/type&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;ant&lt;/groupId&gt;
              &lt;artifactId&gt;ant&lt;/artifactId&gt;
              &lt;version&gt;1.6.5&lt;/version&gt;
              &lt;type&gt;jar&lt;/type&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.apache.tomcat&lt;/groupId&gt;
              &lt;artifactId&gt;tomcat-util&lt;/artifactId&gt;
              &lt;version&gt;9.0.8&lt;/version&gt;
              &lt;type&gt;jar&lt;/type&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.apache.tomcat.embed&lt;/groupId&gt;
              &lt;artifactId&gt;tomcat-embed-core&lt;/artifactId&gt;
              &lt;version&gt;9.0.8&lt;/version&gt;
              &lt;type&gt;jar&lt;/type&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;com.google.code.gson&lt;/groupId&gt;
              &lt;artifactId&gt;gson&lt;/artifactId&gt;
              &lt;version&gt;2.8.2&lt;/version&gt;
              &lt;type&gt;jar&lt;/type&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;com.vividsolutions&lt;/groupId&gt;
              &lt;artifactId&gt;jts-core&lt;/artifactId&gt;
              &lt;version&gt;1.14.0&lt;/version&gt;
              &lt;type&gt;jar&lt;/type&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.geotools&lt;/groupId&gt;
              &lt;artifactId&gt;gt-postgis&lt;/artifactId&gt;
              &lt;version&gt;2.7.3&lt;/version&gt;
              &lt;type&gt;jar&lt;/type&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;javax&lt;/groupId&gt;
              &lt;artifactId&gt;javaee-web-api&lt;/artifactId&gt;
              &lt;version&gt;6.0&lt;/version&gt;
              &lt;type&gt;jar&lt;/type&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;log4j&lt;/groupId&gt;
              &lt;artifactId&gt;log4j&lt;/artifactId&gt;
              &lt;version&gt;1.2.17&lt;/version&gt;
      &lt;/dependency&gt;
          &lt;!-- https://mvnrepository.com/artifact/org.geotools.jdbc/gt-jdbc-postgis --&gt;
      &lt;/dependencies&gt;
      &lt;repositories&gt;
  &lt;!--      &lt;repository&gt;
              &lt;id&gt;maven2-repository.dev.java.net&lt;/id&gt;
              &lt;name&gt;Java.net repository&lt;/name&gt;
              &lt;url&gt;http://download.java.net/maven/2&lt;/url&gt;
          &lt;/repository&gt;--&gt;
  
          &lt;repository&gt;
              &lt;id&gt;osgeo&lt;/id&gt;
              &lt;name&gt;Open Source Geospatial Foundation Repository&lt;/name&gt;
              &lt;url&gt;http://download.osgeo.org/webdav/geotools/&lt;/url&gt;
          &lt;/repository&gt;
          &lt;repository&gt;
            &lt;snapshots&gt;
              &lt;enabled&gt;true&lt;/enabled&gt;
            &lt;/snapshots&gt;
            &lt;id&gt;boundless&lt;/id&gt;
            &lt;name&gt;Boundless Maven Repository&lt;/name&gt;
            &lt;url&gt;http://repo.boundlessgeo.com/main&lt;/url&gt;
          &lt;/repository&gt;
      &lt;/repositories&gt;
  
      &lt;build&gt;
          &lt;plugins&gt;
              &lt;plugin&gt;
                  &lt;inherited&gt;true&lt;/inherited&gt;
                  &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
                  &lt;artifactId&gt;maven-compiler-plugin&lt;/artifactId&gt;
                  &lt;configuration&gt;
                      &lt;source&gt;1.8&lt;/source&gt;
                      &lt;target&gt;1.8&lt;/target&gt;
                  &lt;/configuration&gt;
              &lt;/plugin&gt;
          &lt;/plugins&gt;
      &lt;/build&gt;
  &lt;/project&gt;
  </code></pre>
  
  <p><strong>EDIT</strong> Updated error logs</p>
  
  <pre><code>Exception in thread "main" java.lang.NoClassDefFoundError: org/geotools/data/jdbc/JDBCDataStore
      at java.lang.ClassLoader.defineClass1(Native Method)
      at java.lang.ClassLoader.defineClass(ClassLoader.java:760)
      at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
      at java.net.URLClassLoader.defineClass(URLClassLoader.java:467)
      at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
      at java.net.URLClassLoader$1.run(URLClassLoader.java:368)
      at java.net.URLClassLoader$1.run(URLClassLoader.java:362)
      at java.security.AccessController.doPrivileged(Native Method)
      at java.net.URLClassLoader.findClass(URLClassLoader.java:361)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
      at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
      at org.geotools.data.postgis.PostgisDataStoreFactory.createDataStoreInternal(PostgisDataStoreFactory.java:237)
      at org.geotools.data.postgis.PostgisDataStoreFactory.createDataStore(PostgisDataStoreFactory.java:208)
      at org.geotools.data.postgis.PostgisDataStoreFactory.createDataStore(PostgisDataStoreFactory.java:46)
      at org.geotools.data.DataAccessFinder.getDataStore(DataAccessFinder.java:121)
      at org.geotools.data.DataStoreFinder.getDataStore(DataStoreFinder.java:71)
      at org.geotools.geoshapesave.saveShape.main(saveShape.java:77)
  Caused by: java.lang.ClassNotFoundException: org.geotools.data.jdbc.JDBCDataStore
      at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
      at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
      ... 18 more
  </code></pre>