This is an automated email from the ASF dual-hosted git repository.

ntimofeev pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/cayenne.git

commit 0ec693bf64dfd1c81868b3d5a974aeabc4895658
Author: Nikita Timofeev <stari...@gmail.com>
AuthorDate: Wed Sep 11 11:28:12 2019 +0300

    CAY-2615 Saving project throws IllegalArgumentException
---
 .../src/main/java/org/apache/cayenne/gen/CgenConfiguration.java  | 9 +++++++--
 .../main/java/org/apache/cayenne/gen/xml/CgenSaverDelegate.java  | 8 +++++---
 2 files changed, 12 insertions(+), 5 deletions(-)

diff --git 
a/cayenne-cgen/src/main/java/org/apache/cayenne/gen/CgenConfiguration.java 
b/cayenne-cgen/src/main/java/org/apache/cayenne/gen/CgenConfiguration.java
index 71055f0..2f6e2e4 100644
--- a/cayenne-cgen/src/main/java/org/apache/cayenne/gen/CgenConfiguration.java
+++ b/cayenne-cgen/src/main/java/org/apache/cayenne/gen/CgenConfiguration.java
@@ -166,8 +166,13 @@ public class CgenConfiguration implements Serializable, 
XMLSerializable {
         this.relPath = relPath;
     }
 
-    public void setRelPath(String path) {
-               this.relPath = rootPath != null ? 
rootPath.relativize(Paths.get(path)) : Paths.get(path);
+    public void setRelPath(String pathStr) {
+        Path path = Paths.get(pathStr);
+        if(path.isAbsolute() && rootPath != null) {
+            this.relPath = rootPath.relativize(path);
+        } else {
+            this.relPath = path;
+        }
        }
 
     public boolean isOverwrite() {
diff --git 
a/cayenne-cgen/src/main/java/org/apache/cayenne/gen/xml/CgenSaverDelegate.java 
b/cayenne-cgen/src/main/java/org/apache/cayenne/gen/xml/CgenSaverDelegate.java
index fc75f06..b616b10 100644
--- 
a/cayenne-cgen/src/main/java/org/apache/cayenne/gen/xml/CgenSaverDelegate.java
+++ 
b/cayenne-cgen/src/main/java/org/apache/cayenne/gen/xml/CgenSaverDelegate.java
@@ -55,7 +55,6 @@ public class CgenSaverDelegate extends BaseSaverDelegate{
         if(cgenConfiguration.getRootPath() == null) {
             return;
         }
-        Path prevPath = cgenConfiguration.buildPath();
         URL url = getBaseDirectory().getURL();
         if(url != null) {
             Path resourcePath;
@@ -68,9 +67,12 @@ public class CgenSaverDelegate extends BaseSaverDelegate{
                 resourcePath = resourcePath.getParent();
             }
             cgenConfiguration.setRootPath(resourcePath);
+            Path prevPath = cgenConfiguration.buildPath();
             if(prevPath != null) {
-                Path relPath = resourcePath.relativize(prevPath).normalize();
-                cgenConfiguration.setRelPath(relPath);
+                if(prevPath.isAbsolute()) {
+                    Path relPath = 
resourcePath.relativize(prevPath).normalize();
+                    cgenConfiguration.setRelPath(relPath);
+                }
                 Path templatePath = Paths.get(cgenConfiguration.getTemplate());
                 if(templatePath.isAbsolute()) {
                     
cgenConfiguration.setTemplate(resourcePath.relativize(templatePath).normalize().toString());

Reply via email to