[ https://issues.apache.org/jira/browse/JCR-3035?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14190019#comment-14190019 ]
Magnus Backström commented on JCR-3035: --------------------------------------- I am having this exact problem in version 2.2.13, I believe it should be reopened... > NullPointerException if accessing VersionHistory before checkin() > ----------------------------------------------------------------- > > Key: JCR-3035 > URL: https://issues.apache.org/jira/browse/JCR-3035 > Project: Jackrabbit Content Repository > Issue Type: Bug > Affects Versions: 2.2.5, 2.2.7 > Reporter: Flavio Donzé > Assignee: Julian Reschke > Priority: Critical > > I'm trying to update our software from Jackrabbit 2.2.4 to 2.2.7, I also > tried version 2.2.5. > If I access the version history before calling VersionManager.checkin(), I > get an NullPointerException. Bellow the stacktrace: > java.lang.NullPointerException > at > org.apache.jackrabbit.core.ItemManager.getDefinition(ItemManager.java:206) > at org.apache.jackrabbit.core.ItemData.getDefinition(ItemData.java:99) > at org.apache.jackrabbit.core.ItemManager.canRead(ItemManager.java:409) > at > org.apache.jackrabbit.core.ItemManager.createItemData(ItemManager.java:804) > at > org.apache.jackrabbit.core.ItemManager.getItemData(ItemManager.java:379) > at org.apache.jackrabbit.core.ItemManager.getItem(ItemManager.java:316) > at org.apache.jackrabbit.core.ItemManager.getItem(ItemManager.java:610) > at > org.apache.jackrabbit.core.SessionImpl.getNodeById(SessionImpl.java:493) > at > org.apache.jackrabbit.core.VersionManagerImpl$1.perform(VersionManagerImpl.java:122) > at > org.apache.jackrabbit.core.VersionManagerImpl$1.perform(VersionManagerImpl.java:114) > at > org.apache.jackrabbit.core.session.SessionState.perform(SessionState.java:200) > at > org.apache.jackrabbit.core.VersionManagerImpl.perform(VersionManagerImpl.java:95) > at > org.apache.jackrabbit.core.VersionManagerImpl.checkin(VersionManagerImpl.java:114) > at > org.apache.jackrabbit.core.VersionManagerImpl.checkin(VersionManagerImpl.java:100) > at > com.softmodeler.repository.service.impl.RepositoryService.test(RepositoryService.java:294) > ... > I created a code snippet (mixed together from a bunch of own service > methods), the second execution of test() should reproduce the exception. > If the "if (!isNew)" block is replaced with versionLabel = "1.0"; , the code > runs through. > @Transactional(propagation = Propagation.REQUIRED, rollbackFor = > Exception.class) > public void test() { > try { > Session session = repository.login(CREDENTIALS, WORKSPACE); > Node root = session.getRootNode(); > Node dataNode = null; > if (root.hasNode("test")) { > dataNode = root.getNode("test"); > } else { > dataNode = root.addNode("test", JcrConstants.NT_FOLDER); > } > Node fileNode = null; > String fileName = "test3.xml"; > if (!dataNode.hasNode(fileName)) { > File file = new File("D:/temp/" + fileName); > fileNode = createOrUpdateFileNode(dataNode, new > FileInputStream(file), file.getName()); > } else { > fileNode = dataNode.getNode(fileName); > } > String versionLabel = null; > boolean isNew = fileNode.isNew(); > if (!isNew) { > VersionManager versionManager = > session.getWorkspace().getVersionManager(); > String[] versionLabels = > versionManager.getVersionHistory(fileNode.getPath()).getVersionLabels(); > if (versionLabels.length > 0) { > Arrays.sort(versionLabels, versionComparator); > String[] segment = > versionLabels[versionLabels.length - 1].split("\\."); //$NON-NLS-1$ > Integer minor = Integer.valueOf(segment[1]); > String newVersion = segment[0] + "." + (minor + > 1); //$NON-NLS-1$ > versionLabel = newVersion; > } > } > VersionManager versionManager = > session.getWorkspace().getVersionManager(); > if (isNew) { > fileNode.addMixin(JcrConstants.MIX_VERSIONABLE); > } > session.save(); > logger.debug("checkout production node", fileNode.getPath()); > //$NON-NLS-1$ > versionManager.checkout(fileNode.getPath()); > session.save(); > Version currentVersion = > versionManager.checkin(fileNode.getPath()); > if (versionLabel == null) { > versionLabel = "0.1"; //$NON-NLS-1$ > } > > versionManager.getVersionHistory(fileNode.getPath()).addVersionLabel(currentVersion.getName(), > versionLabel, true); > session.logout(); > } catch (Exception e) { > e.printStackTrace(); > } > } > @Transactional(propagation = Propagation.REQUIRED, rollbackFor = > Exception.class) > protected Node createOrUpdateFileNode(Node parent, InputStream stream, String > name) throws Exception { > Node fileNode = null; > Node resNode = null; > if (!parent.hasNode(name)) { > fileNode = parent.addNode(name, JcrConstants.NT_FILE); > resNode = fileNode.addNode(JcrConstants.JCR_CONTENT, > JcrConstants.NT_RESOURCE); > } else { > fileNode = parent.getNode(name); > resNode = fileNode.getNode(JcrConstants.JCR_CONTENT); > } > String type = mimetypesFileTypeMap.getContentType(name); > resNode.setProperty(JcrConstants.JCR_MIMETYPE, type != null ? type : > ""); //$NON-NLS-1$ > resNode.setProperty(JcrConstants.JCR_LASTMODIFIED, > Calendar.getInstance()); > Binary binary = new BinaryImpl(stream); > resNode.setProperty(JcrConstants.JCR_DATA, binary); > binary.dispose(); > stream.close(); > return fileNode; > } -- This message was sent by Atlassian JIRA (v6.3.4#6332)