数据=(字符串)剪贴板.getData(DataFlavor.stringFlavor)抛出java.lang.StringIndexOutOfBoundsException:开头0,结尾-1,长度1888

时间:2019-06-14 17:50:29

标签: java

我使用Clipboard类获取位于剪贴板中的文本。但是data =(String)Clipboard.getData(DataFlavor.stringFlavor)抛出异常StringIndexOutOfBoundsException(id = 107)
我不知道为什么会这样。

/**
 * 
 * @param insert - inserts specific entity into database
 * @param fetch - fetches specific entity that has or will be inserted into database
 * @param <T> type of entity being inserted
 * @return
 */
@Transactional(propagation = Propagation.REQUIRES_NEW, isolation = Isolation.READ_COMMITTED)
public <T> T getOrInsertWithUniqueConstraints(Supplier<T> insert, Supplier<Optional<T>> fetch){
    try {
        Optional<T> entityInstance = fetch.get();
        return entityInstance.orElse(insert.get());
    }
    catch (DuplicateKeyException dke){
        Optional<T> entityAlreadyInserted = fetch.get();
        return entityAlreadyInserted.get();
    }
}

0 个答案:

没有答案