Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fastddsgen hang when using two -I options pointing to the same folder [13740] #78

Open
NickKornweibel opened this issue Dec 14, 2021 · 0 comments
Labels

Comments

@NickKornweibel
Copy link

NickKornweibel commented Dec 14, 2021

The following command uses -I options both pointing to the same "other" folder
fastddsgen -replace -cs -I base/ -I other/ -I /home/eltdev/tmp/fastddsgen_bug/other/ sub/IcdTypesComplexTest.idl

It cases the tool to hang.

Patch applied to resolve the issue:

 .../java/com/eprosima/fastdds/fastddsgen.java | 37 ++++++++++++++++++-
 1 file changed, 36 insertions(+), 1 deletion(-)

diff --git a/src/main/java/com/eprosima/fastdds/fastddsgen.java b/src/main/java/com/eprosima/fastdds/fastddsgen.java
index 48f3a1e..d193251 100644
--- a/src/main/java/com/eprosima/fastdds/fastddsgen.java
+++ b/src/main/java/com/eprosima/fastdds/fastddsgen.java
@@ -40,8 +40,12 @@ import java.io.FileNotFoundException;
 import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
+import java.io.IOError;
 import java.io.InputStreamReader;
 import java.io.OutputStream;
+import java.nio.file.InvalidPathException;
+import java.nio.file.Path;
+import java.nio.file.Paths;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Vector;
@@ -281,7 +285,10 @@ public class fastddsgen
             {
                 if (count < args.length)
                 {
-                    m_includePaths.add("-I".concat(args[count++]));
+                    String pathStr = args[count++];
+                    if (!isIncludePathDuplicated(pathStr)) {
+                        m_includePaths.add("-I".concat(pathStr));
+                    }
                 }
                 else
                 {
@@ -306,6 +313,34 @@ public class fastddsgen
 
     }
 
+    private boolean isIncludePathDuplicated(String pathToCheck) {
+        try {
+            Path path = Paths.get(pathToCheck);
+            String absPath = path.toAbsolutePath().toString();
+            boolean isDuplicateFound = false;
+            for (String includePath : m_includePaths) {
+                // include paths are prefixed with "-I"
+                if (includePath.length() <= 2) {
+                    continue;
+                }
+                String absIncludePath = Paths.get(includePath.substring(2)).toAbsolutePath().toString();
+                if (absPath.toLowerCase().equals(absIncludePath.toLowerCase())) {
+                    isDuplicateFound = true;
+                    break;
+                }
+            }
+
+            if (isDuplicateFound) {
+                return true;
+            }
+
+        } catch (InvalidPathException | IOError | SecurityException ex) {
+            // path operations failed, just returning false
+        }
+
+        return false;
+    }
+
     /*
      * ----------------------------------------------------------------------------------------
      *
@EduPonz EduPonz transferred this issue from eProsima/Fast-DDS Dec 14, 2021
@JLBuenoLopez JLBuenoLopez changed the title fastddsgen hang when using two -I options pointing to the same folder fastddsgen hang when using two -I options pointing to the same folder [13740] Feb 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants