【问题标题】:Accessing unique closure on List of objects gives UnsupportedOperationException访问对象列表上的唯一闭包会给出 UnsupportedOperationException
【发布时间】:2015-07-20 22:19:30
【问题描述】:

我正在开发 Grails 2.3.11 并且正在使用 MongoDb 插件 mongodb:3.0.3。

我的代码如下所示:

def home() {
   List abcs = ABC.list()
   println abcs.unique { it.parent }
}

代码在访问唯一闭包时中断。

异常说:

ERROR errors.GrailsExceptionResolver- UnsupportedOperationException   occurred when processing request: [GET] /MongoAppInEcomEnv/product/home
Stacktrace follows:
Message: null
Line | Method
->>  148 | add       in java.util.AbstractList
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|    108 | add       in     ''
|    342 | addAll .  in java.util.AbstractCollection
|    120 | $tt__home in com.test.aitm.ProductController$$EPCH6LtA
|    198 | doFilter  in grails.plugin.cache.web.filter.PageFragmentCachingFilter
|     63 | doFilter  in grails.plugin.cache.web.filter.AbstractFilter
|   1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
|    615 | run       in java.util.concurrent.ThreadPoolExecutor$Worker
^    744 | run . . . in java.lang.Thread

【问题讨论】:

  • 您能否将第 120 行与您的代码联系起来。那里的列表是否包含空对象?例如it.parent 会因为 itbeeing null 而失败吗?
  • 嗨@cfrick,我已经检查过了,它在集合中不为空。 Infact null 不能退出,因为父字段可以为空:false。
  • 如果是 ProductController,请向我们展示代码行 120

标签: mongodb grails grails-orm


【解决方案1】:

列表好像是空的。

你也可以试试

abcs.parent.unique()

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-01-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-01-26
    • 2014-03-13
    相关资源
    最近更新 更多