jackrabbit-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Matthias Reischenbacher (Commented) (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (JCR-3035) NullPointerException if accessing VersionHistory before checkin()
Date Thu, 08 Dec 2011 12:44:40 GMT

    [ https://issues.apache.org/jira/browse/JCR-3035?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13165190#comment-13165190
] 

Matthias Reischenbacher commented on JCR-3035:
----------------------------------------------

The NPE is fixed but the check-in operation still fails during a transaction. That's the new
stack trace:

Caused by: javax.jcr.InvalidItemStateException: Could not find child 3b99e73e-332f-4bc1-82a0-ee1482710c3c
of node 434ce20f-cae2-4488-b178-1f697690c5d2
	at org.apache.jackrabbit.core.ItemManager.getDefinition(ItemManager.java:207) ~[jackrabbit-core-2.2.10.jar:2.2.10]
	at org.apache.jackrabbit.core.ItemData.getDefinition(ItemData.java:99) ~[jackrabbit-core-2.2.10.jar:2.2.10]
	at org.apache.jackrabbit.core.ItemManager.canRead(ItemManager.java:421) ~[jackrabbit-core-2.2.10.jar:2.2.10]
	at org.apache.jackrabbit.core.ItemManager.createItemData(ItemManager.java:843) ~[jackrabbit-core-2.2.10.jar:2.2.10]
	at org.apache.jackrabbit.core.ItemManager.getItemData(ItemManager.java:391) ~[jackrabbit-core-2.2.10.jar:2.2.10]
	at org.apache.jackrabbit.core.ItemManager.getItem(ItemManager.java:328) ~[jackrabbit-core-2.2.10.jar:2.2.10]
	at org.apache.jackrabbit.core.ItemManager.getItem(ItemManager.java:622) ~[jackrabbit-core-2.2.10.jar:2.2.10]
	at org.apache.jackrabbit.core.SessionImpl.getNodeById(SessionImpl.java:493) ~[jackrabbit-core-2.2.10.jar:2.2.10]
	at org.apache.jackrabbit.core.VersionManagerImpl$1.perform(VersionManagerImpl.java:123) ~[jackrabbit-core-2.2.10.jar:2.2.10]
	at org.apache.jackrabbit.core.VersionManagerImpl$1.perform(VersionManagerImpl.java:115) ~[jackrabbit-core-2.2.10.jar:2.2.10]
	at org.apache.jackrabbit.core.session.SessionState.perform(SessionState.java:200) ~[jackrabbit-core-2.2.10.jar:2.2.10]
	at org.apache.jackrabbit.core.VersionManagerImpl.perform(VersionManagerImpl.java:96) ~[jackrabbit-core-2.2.10.jar:2.2.10]
	at org.apache.jackrabbit.core.VersionManagerImpl.checkin(VersionManagerImpl.java:115) ~[jackrabbit-core-2.2.10.jar:2.2.10]
	at org.apache.jackrabbit.core.VersionManagerImpl.checkin(VersionManagerImpl.java:101) ~[jackrabbit-core-2.2.10.jar:2.2.10]
	at org.apache.jackrabbit.core.NodeImpl.checkin(NodeImpl.java:2830) ~[jackrabbit-core-2.2.10.jar:2.2.10]

Should I create a separate issue?
                
> 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é
>            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 is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

       

Mime
View raw message