{"action":"opened","issue":{"url":"https://api.github.com/repos/phax/jcodemodel/issues/27","labels_url":"https://api.github.com/repos/phax/jcodemodel/issues/27/labels{/name}","comments_url":"https://api.github.com/repos/phax/jcodemodel/issues/27/comments","events_url":"https://api.github.com/repos/phax/jcodemodel/issues/27/events","html_url":"https://github.com/phax/jcodemodel/issues/27","id":100374546,"number":27,"title":"JPackage.parent() cannot walk to root package","user":{"login":"davekipfer","id":5419261,"avatar_url":"https://avatars.githubusercontent.com/u/5419261?v=3","gravatar_id":"","url":"https://api.github.com/users/davekipfer","html_url":"https://github.com/davekipfer","followers_url":"https://api.github.com/users/davekipfer/followers","following_url":"https://api.github.com/users/davekipfer/following{/other_user}","gists_url":"https://api.github.com/users/davekipfer/gists{/gist_id}","starred_url":"https://api.github.com/users/davekipfer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/davekipfer/subscriptions","organizations_url":"https://api.github.com/users/davekipfer/orgs","repos_url":"https://api.github.com/users/davekipfer/repos","events_url":"https://api.github.com/users/davekipfer/events{/privacy}","received_events_url":"https://api.github.com/users/davekipfer/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2015-08-11T18:22:13Z","updated_at":"2015-08-11T18:22:13Z","closed_at":null,"body":"When producing a code model using JCodeModel.ref(<clazz>), the following operation doesn't work as expected:\r\n\r\n<code>\r\n// Create JCodeModel\r\n\r\nJCodeModel wModel = new JCodeModel();\r\n\r\n\r\n// Reflect into class\r\n\r\n\r\nAbstractJClass wClass = wModel.ref(com.redfish.prod.Boomer.class);\r\n\r\n\r\n// Walk up to the root package\r\n\r\n\r\nJPackage wCurrentPackage = null;\r\n\r\nfor (wCurrentPackage = wClass._package(); wCurrentPackage.parent() != null; wCurrentPackage = wCurrentPackage.parent());\r\n\r\nJPackage wRoot = wCurrentPackage;\r\n\r\n</code>\r\n\r\nThe problem occurs in JPackage.parent() on the package just above the root package.  The name is just \"com\", and so the existing code:\r\n\r\n<code>\r\n  /**\r\n   * Gets the parent package, or null if this class is the root package.\r\n   */\r\n\r\n  @Nullable\r\n\r\n  public JPackage parent ()\r\n\r\n  {\r\n\r\n    if (m_sName.length () == 0)\r\n\r\n      return null;\r\n\r\n\r\n    final int idx = m_sName.lastIndexOf ('.');\r\n\r\n    return m_aOwner._package (m_sName.substring (0, idx));\r\n\r\n  }\r\n\r\n</code>\r\n\r\nThe result in the lowest level non-root package is a StringIndexOutOfBoundsException as \"idx\" is set to -1.\r\n\r\nThis seems to be correct usage based on what I seei in the method's documentation, but clearly it can't handle it.\r\n"}}