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

String handling errors while generating pojos #8

Closed
pharsfalvi opened this issue Oct 25, 2014 · 3 comments
Closed

String handling errors while generating pojos #8

pharsfalvi opened this issue Oct 25, 2014 · 3 comments

Comments

@pharsfalvi
Copy link
Contributor

Hi
I've tried to generate the pojos for one of my mysq databases and faced the following problems.

Stage 2: Getting commit order in 'PARTIAL' strategy
java.lang.StringIndexOutOfBoundsException: String index out of range: -1
    at java.lang.String.substring(String.java:1911)
    at com.felees.hbnpojogen.SyncUtils.getTableCatalog(SyncUtils.java:1295)
    at com.felees.hbnpojogen.SyncUtils.getCommitOrder(SyncUtils.java:159)
    at com.felees.hbnpojogen.SyncUtils.getCommitOrder(SyncUtils.java:501)
    at com.felees.hbnpojogen.HbnPojoGen.sync(HbnPojoGen.java:172)
    at com.felees.hbnpojogen.HbnPojoGen.run(HbnPojoGen.java:461)
    at com.felees.hbnpojogen.HbnPojoGen.main(HbnPojoGen.java:495)


Stage 4: Building object model
null
java.lang.NullPointerException
    at com.felees.hbnpojogen.SyncUtils.removeUnderscores(SyncUtils.java:992)
    at com.felees.hbnpojogen.obj.Clazz.setClassPackage(Clazz.java:1040)
    at com.felees.hbnpojogen.Core.buildObjectModel(Core.java:768)
    at com.felees.hbnpojogen.HbnPojoGen.sync(HbnPojoGen.java:222)
    at com.felees.hbnpojogen.HbnPojoGen.run(HbnPojoGen.java:461)
    at com.felees.hbnpojogen.HbnPojoGen.main(HbnPojoGen.java:495)
...
Stage 6: Writing interfaces
java.lang.StringIndexOutOfBoundsException: String index out of range: 1
    at java.lang.String.substring(String.java:1907)
    at com.felees.hbnpojogen.SyncUtils.upfirstChar(SyncUtils.java:814)
    at com.felees.hbnpojogen.obj.Clazz.getDataLayerInterfaceFullClassName(Clazz.java:1617)
    at com.felees.hbnpojogen.obj.Clazz.getDataLayerImplFullClassName(Clazz.java:1516)
    at com.felees.hbnpojogen.VelocityWriters.writeClass(VelocityWriters.java:485)
    at com.felees.hbnpojogen.VelocityWriters.writeInterfaceClasses(VelocityWriters.java:767)
    at com.felees.hbnpojogen.HbnPojoGen.sync(HbnPojoGen.java:236)
    at com.felees.hbnpojogen.HbnPojoGen.run(HbnPojoGen.java:461)
    at com.felees.hbnpojogen.HbnPojoGen.main(HbnPojoGen.java:495)
@pharsfalvi
Copy link
Contributor Author

Here is the patch which made it work for me

From 81c3ea3a561b980670886087da8041825b7f44cb Mon Sep 17 00:00:00 2001
From: pharsfalvi <peter@qtc.hu>
Date: Sat, 25 Oct 2014 18:23:54 +0200
Subject: [PATCH] String handling errors while generating pojos

---
 .../src/main/java/com/felees/hbnpojogen/SyncUtils.java      | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/hbnpojogen-core/src/main/java/com/felees/hbnpojogen/SyncUtils.java b/hbnpojogen-core/src/main/java/com/felees/hbnpojogen/SyncUtils.java
index dfe7df2..34fb1e5 100755
--- a/hbnpojogen-core/src/main/java/com/felees/hbnpojogen/SyncUtils.java
+++ b/hbnpojogen-core/src/main/java/com/felees/hbnpojogen/SyncUtils.java
@@ -811,6 +811,9 @@ implements Serializable {
     * @return the same string with the first character set to uppercase
     */
    public static String upfirstChar(String s) {
+        if (s == null || s.length() == 0){
+            return "";
+        }
        return s.substring(0, 1).toUpperCase() + s.substring(1, s.length());
    }

@@ -982,8 +985,9 @@ implements Serializable {
     */
    public static String removeUnderscores(String input) {
        StringBuffer result = new StringBuffer();
-
-       if (State.getInstance().disableUnderscoreConversion) {
+        if (input == null){
+            return "";
+        } else if (State.getInstance().disableUnderscoreConversion) {
            result.append(input);
        }
        else {
@@ -1292,7 +1296,10 @@ implements Serializable {
     * @return The table catalog
     */
    public static String getTableCatalog(String dottedInput) {
-       return dottedInput.substring(0, dottedInput.indexOf("."));
+        if (dottedInput.indexOf(".") >= 0){
+            return dottedInput.substring(0, dottedInput.indexOf("."));
+        }
+        return dottedInput;
    }


-- 
2.0.1

@wwadge
Copy link
Owner

wwadge commented Oct 25, 2014

Hi, thanks for the patch -- if possible can you raise a pull request? It just makes it easier to manage and track.

@pharsfalvi
Copy link
Contributor Author

Yup, it's done. Cheers
Peter

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants