Details
Description
Currently, renaming a project key won't rename the key of disabled components for this project.
This may have nasty consequences.
Consider the following use case.
Project with key A has two files, one is deleted:
- file C which key is A:C
- deleted file D which key is A:D
Key of project is renamed to B. Files are now:
- file C which key is B:C
- deleted file D which key is still A:D
User now analyses again project A and file D is restored. This analysis will fail with an error such as the following:
2018.03.15 19:15:43 ERROR ce[AWIq3DRnV4Tcj4EG2a1W][o.s.c.t.CeWorkerImpl] Failed to execute task AWIq3DRnV4Tcj4EG2a1W org.sonar.server.computation.task.projectanalysis.component.VisitException: Visit failed for Component {key=org.galatea:fuse-starter-java:src/test/java/org/galatea/starter/domain,type=DIRECTORY} located org.gal atea:fuse-starter-java(type=PROJECT) at org.sonar.server.computation.task.projectanalysis.component.VisitException.rethrowOrWrap(VisitException.java:44) at org.sonar.server.computation.task.projectanalysis.component.PathAwareCrawler.visit(PathAwareCrawler.java:52) at org.sonar.server.computation.task.projectanalysis.component.PathAwareCrawler.visitChildren(PathAwareCrawler.java:87) at org.sonar.server.computation.task.projectanalysis.component.PathAwareCrawler.visitImpl(PathAwareCrawler.java:70) at org.sonar.server.computation.task.projectanalysis.component.PathAwareCrawler.visit(PathAwareCrawler.java:50) at org.sonar.server.computation.task.projectanalysis.step.PersistComponentsStep.execute(PersistComponentsStep.java:111) at org.sonar.server.computation.task.step.ComputationStepExecutor.executeSteps(ComputationStepExecutor.java:64) at org.sonar.server.computation.task.step.ComputationStepExecutor.execute(ComputationStepExecutor.java:52) at org.sonar.server.computation.task.projectanalysis.taskprocessor.ReportTaskProcessor.process(ReportTaskProcessor.java:73) at org.sonar.ce.taskprocessor.CeWorkerImpl.executeTask(CeWorkerImpl.java:134) at org.sonar.ce.taskprocessor.CeWorkerImpl.findAndProcessTask(CeWorkerImpl.java:97) at org.sonar.ce.taskprocessor.CeWorkerImpl.withCustomizedThreadName(CeWorkerImpl.java:81) at org.sonar.ce.taskprocessor.CeWorkerImpl.call(CeWorkerImpl.java:73) at org.sonar.ce.taskprocessor.CeWorkerImpl.call(CeWorkerImpl.java:43) at java.util.concurrent.FutureTask.run(FutureTask.java:266) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) at java.util.concurrent.FutureTask.run(FutureTask.java:266) at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180) at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) at java.lang.Thread.run(Thread.java:748) Caused by: org.apache.ibatis.exceptions.PersistenceException: ### Error updating database. Cause: org.postgresql.util.PSQLException: ERROR: duplicate key value violates unique constraint "projects_kee" Detail: Key (kee)=(org.galatea:fuse-starter-java:src/test/java/org/galatea/starter/domain) already exists. ### The error may involve org.sonar.db.component.ComponentMapper.insert-Inline ### The error occurred while setting parameters ### Cause: org.postgresql.util.PSQLException: ERROR: duplicate key value violates unique constraint "projects_kee" Detail: Key (kee)=(org.galatea:fuse-starter-java:src/test/java/org/galatea/starter/domain) already exists. at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:30) at org.apache.ibatis.session.defaults.DefaultSqlSession.update(DefaultSqlSession.java:200) at org.apache.ibatis.session.defaults.DefaultSqlSession.insert(DefaultSqlSession.java:185) at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:57) at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:59) at com.sun.proxy.$Proxy35.insert(Unknown Source) at org.sonar.db.component.ComponentDao.insert(ComponentDao.java:325) at org.sonar.server.computation.task.projectanalysis.step.PersistComponentsStep$PersistComponentStepsVisitor.persistComponent(PersistComponentsStep.java:252) at org.sonar.server.computation.task.projectanalysis.step.PersistComponentsStep$PersistComponentStepsVisitor.persistAndPopulateCache(PersistComponentsStep.java:244) at org.sonar.server.computation.task.projectanalysis.step.PersistComponentsStep$PersistComponentStepsVisitor.visitDirectory(PersistComponentsStep.java:216) at org.sonar.server.computation.task.projectanalysis.component.PathAwareCrawler.visitNode(PathAwareCrawler.java:102) at org.sonar.server.computation.task.projectanalysis.component.PathAwareCrawler.visitImpl(PathAwareCrawler.java:67) at org.sonar.server.computation.task.projectanalysis.component.PathAwareCrawler.visit(PathAwareCrawler.java:50) ... 20 common frames omitted Caused by: org.postgresql.util.PSQLException: ERROR: duplicate key value violates unique constraint "projects_kee" Detail: Key (kee)=(org.galatea:fuse-starter-java:src/test/java/org/galatea/starter/domain) already exists. at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2422) at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:2167) at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:306) at org.postgresql.jdbc.PgStatement.executeInternal(PgStatement.java:441) at org.postgresql.jdbc.PgStatement.execute(PgStatement.java:365) at org.postgresql.jdbc.PgPreparedStatement.executeWithFlags(PgPreparedStatement.java:155) at org.postgresql.jdbc.PgPreparedStatement.execute(PgPreparedStatement.java:144) at org.apache.commons.dbcp.DelegatingPreparedStatement.execute(DelegatingPreparedStatement.java:172) at org.apache.commons.dbcp.DelegatingPreparedStatement.execute(DelegatingPreparedStatement.java:172) at org.apache.ibatis.executor.statement.PreparedStatementHandler.update(PreparedStatementHandler.java:46) at org.apache.ibatis.executor.statement.RoutingStatementHandler.update(RoutingStatementHandler.java:74) at org.apache.ibatis.executor.ReuseExecutor.doUpdate(ReuseExecutor.java:52) at org.apache.ibatis.executor.BaseExecutor.update(BaseExecutor.java:117) at org.apache.ibatis.executor.CachingExecutor.update(CachingExecutor.java:76) at org.apache.ibatis.session.defaults.DefaultSqlSession.update(DefaultSqlSession.java:198) ... 31 common frames omitted
The explanation is the following.
In the described used case above where file D is added back, we will try and persist component for file D with key A:D. Unfortunately, this component already exist under project B with key A:D and the insert fails.
Attachments
Issue Links
- is related to
-
SONAR-10536 It's no longer possible to analyse a module that was removed from another project
-
- Closed
-